System.out.printf("%s你好啊,%s你吗的","呵呵","ff");//%s代表字符串System.out.printf("%s!This is my %dth Java Program!","C language Fans",3);2.打印乘法表
while(true){ System.out.println("输入乘法表打印数范围:"); boolean isRightfulNum = true; Scanner s = null; int num=0; do{ s = new Scanner(System.in); try { num = s.nextInt(); isRightfulNum = true; } catch (Exception e) { System.err.println("请输入合法的数字:"); isRightfulNum = false; } }while(!isRightfulNum); System.out.printf("你要打印的范围是%d*%d\n", num, num); for(int i=1;i<=num;i++){ for(int j=1;j<=i;j++){ System.out.printf("%d*%d=%d",i,j,i*j); System.out.print(" "); } System.out.println(); }}3.判断奇偶数
Scanner s = null;int num = 0;do{ System.out.println("请输入要判断的数字:"); boolean isRightNum = true; do{ s = new Scanner(System.in); try { num = s.nextInt(); isRightNum = true; } catch (Exception e) { System.err.println("请输入正确的数字:"); isRightNum = false; } }while(!isRightNum); if(num%2==0){ System.out.printf("%d是偶数",num); }else{ System.out.printf("%d是奇数",num); } System.out.println("是否继续?1继续其他键离开"); num = s.nextInt();}while(num==1);