import java.io.*; public class Prog25{ public static void main(String[] args){ int n = 0; System.out.print("请输入一个5位数:"); BufferedReader bufin = new BufferedReader(new InputStreamReader(System.in)); try{ n = Integer.parseInt(bufin.readLine()); }catch(IOException e){ e.printStackTrace(); }finally{ try{ bufin.close(); }catch(IOException e){ e.printStackTrace(); } } palin(n); } private static void palin(int n){ int m = n; int[] a = new int[5]; if(n<10000 || n>99999){ System.out.println("输入的不是5位数!"); return; }else{ for(int i=0;i<5;i++){ a = n%10; n /= 10; } if(a[0]==a[4] && a[1]==a[3]) System.out.println(m+"是一个回文数"); else System.out.println(m+"不是回文数"); } } } |
import java.io.*; public class Prog26{ public static void main(String[] args){ String str = new String(); BufferedReader bufIn = new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入星期的英文单词前两至四个字母):"); try{ str = bufIn.readLine(); }catch(IOException e){ e.printStackTrace(); }finally{ try{ bufIn.close(); }catch(IOException e){ e.printStackTrace(); } } week(str); } private static void week(String str){ int n = -1; if(str.trim().equalsIgnoreCase("Mo") || str.trim().equalsIgnoreCase("Mon") || str.trim().equalsIgnoreCase("Mond")) n = 1; if(str.trim().equalsIgnoreCase("Tu") || str.trim().equalsIgnoreCase("Tue") || str.trim().equalsIgnoreCase("Tues")) n = 2; if(str.trim().equalsIgnoreCase("We") || str.trim().equalsIgnoreCase("Wed") || str.trim().equalsIgnoreCase("Wedn")) n = 3; if(str.trim().equalsIgnoreCase("Th") || str.trim().equalsIgnoreCase("Thu") || str.trim().equalsIgnoreCase("Thur")) n = 4; if(str.trim().equalsIgnoreCase("Fr") || str.trim().equalsIgnoreCase("Fri") || str.trim().equalsIgnoreCase("Frid")) n = 5; if(str.trim().equalsIgnoreCase("Sa") || str.trim().equalsIgnoreCase("Sat") || str.trim().equalsIgnoreCase("Satu")) n = 2; if(str.trim().equalsIgnoreCase("Su") || str.trim().equalsIgnoreCase("Sun") || str.trim().equalsIgnoreCase("Sund")) n = 0; switch(n){ case 1: System.out.println("星期一"); break; case 2: System.out.println("星期二"); break; case 3: System.out.println("星期三"); break; case 4: System.out.println("星期四"); break; case 5: System.out.println("星期五"); break; case 6: System.out.println("星期六"); break; case 0: System.out.println("星期日"); break; default: System.out.println("输入有误!"); break; } } } |
public class Prog27{ public static void main(String[] args){ int n = 100; System.out.print(n+"以内的素数:"); for(int i=2;i<n+1;i++){ if(isPrime(i)) System.out.print(i+" "); } } //求素数 private static boolean isPrime(int n){ boolean flag = true; for(int i=2;i<Math.sqrt(n)+1;i++) if(n%i==0){ flag = false; break; } return flag; } } |
public class Prog28{ public static void main(String[] args){ int[] a = new int[]{31,42,21,50,12,60,81,74,101,93}; for(int i=0;i<10;i++) for(int j=0;j<a.length-i-1;j++) if(a[j]>a[j+1]){ int temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } for(int i=0;i<a.length;i++) System.out.print(a+" "); } } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |