public class A {//有多少位数,就添加多少if语句。public static void main(String[] args) { // 二进制转换 er(5); // 八进制转换 ba(9); // 十六进制转换 shiliu(125);}// 二进制转换PRivate static void er(int i) { if (i > 1) { int a = i % 2; i = i / 2; if (i > 1) { int a1 = i % 2; i = i / 2; if (i > 0) { int a2 = i % 2; i = i / 2; System.out.println(a2 + "" + a1 + "" + a); } } }}// 八进制转换private static void ba(int i) { if (i > 1) { int a = i % 8; i = i / 8; if (i > 0) { int a1 = i % 8; i = i / 8; System.out.println(a1 + "" + a); } }}// 十六进制转换private static void shiliu(int i) { String str = null; if (i > 1) { int a = i % 16; i = i / 16; if (a == 10) { str = "A"; } else if (a == 11) { str = "B"; } else if (a == 12) { str = "C"; } else if (a == 13) { str = "D"; } else if (a == 14) { str = "E"; } if (i > 0) { int a1 = i % 16; i = i / 16; System.out.println(a1 + str); } }}
import java.util.Scanner; public class B {public static void main(String[] args) { /*大小写转换*/ char ch = 'f'; switch (ch) { case 'a': System.out.println((char) (ch - 32)); break; case 'b': System.out.println((char) (ch - 32)); break; case 'c': System.out.println((char) (ch - 32)); break; case 'd': System.out.println((char) (ch - 32)); break; case 'e': System.out.println((char) (ch - 32)); break; default: System.out.println("other"); break; } /*判断成绩 注意:要将分数高的过滤排在前面(同类的switch也是如此,将大数写在前面) */ int chengji = 59; if (chengji >= 60) { System.out.println("及格"); } else { System.out.println("不及格"); } switch (chengji / 60) { case 1: System.out.println("及格"); break; case 0: System.out.println("不及格"); break; default: System.out.println("输入的成绩有误"); break; } /* 判断日期为第几天 */ Scanner sc = new Scanner(System.in); System.out.println("请输入年:"); int nian = sc.nextInt(); System.out.println("请输入月:"); int yuefen = sc.nextInt(); System.out.println("请输入天:"); int tian = sc.nextInt(); int sum = 0; if (yuefen >= 1 && yuefen <= 12){ if (yuefen==2) { if((nian % 4 == 0 && nian % 100 !=0) || nian % 400 == 0){ if(tian > 29 && tian <= 31) { System.out.println("输入的天有误"); }else { switch (yuefen) { case 12: sum += 30; case 11: sum += 31; case 10: sum += 30; case 9: sum += 31; case 8: sum += 31; case 7: sum += 30; case 6: sum += 31; case 5: sum += 30; case 4: sum += 31; case 3: if ((nian % 4 == 0 && nian % 100 !=0) || nian % 400 == 0) { sum += 29; } else { sum += 28; } case 2: sum += 31; case 1: sum += tian; System.out.println("输入的日期为" + nian + "年的第" + sum + "天"); break; default: break; } } }else if(tian > 28 && tian <= 31) { System.out.println("输入的天有误"); }else { switch (yuefen) { case 12: sum += 30; case 11: sum += 31; case 10: sum += 30; case 9: sum +=31; case 8: sum += 31; case 7: sum += 30; case 6: sum += 31; case 5: sum += 30; case 4: sum += 31; case 3: if (nian % 4 == 0) { sum += 29; } else { sum += 28; } case 2: sum += 31; case 1: sum += tian; System.out.println("输入的日期为" + nian + "年的第" + sum + "天"); break; default: break; } } } else if (tian <= 31 && tian > 0) { switch (yuefen) { case 12: sum += 30; case 11: sum += 31; case 10: sum += 30; case 9: sum += 31; case 8: sum += 31; case 7: sum += 30; case 6: sum += 31; case 5: sum += 30; case 4: sum += 31; case 3: if (nian % 4 == 0) { sum += 29; } else { sum += 28; } case 2: sum += 31; case 1: sum += tian; System.out.println("输入的日期为" + nian + "年的第" + sum + "天"); break; default: break; } }else{ System.out.println("输入的天有误"); } }else{ System.out.println("输入的月份有误"); } /*判断季节*/ switch (yuefen) { case 3: case 4: case 5: System.out.println("春季"); break; case 6: case 7: case 8: System.out.println("夏季"); break; case 9: case 10: case 11: System.out.println("秋季"); break; case 12: case 1: case 2: System.out.println("冬季"); break; default: System.out.println("输入的月份有误"); break; } /*互换*/ int m=12; int n=5; System.out.println(m+","+n); m=m^n;//m=12^5=9 n=m^n;//n=9^5=12 m=m^n;//m=9^12=5 System.out.println(m+","+n);}