package com.one; import java.util.Scanner; public class LiuChengKongZhi { public static void main(String[] args){ //流程控制 /**1、判断2008年是否 是闰年; * 判断条件:能被4整除,但是不能被100整除, * 能被400整除 int year = 2008; if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ){ System.out.println(year + "是闰年"); } else{ System.out.println(year + "不是闰年"); } */ /**打印 for(int i = 1; i < 11;i++){ for(int j = 1; j <= i;j++){ System.out.print("*"); } System.out.println(); } */ /**打印 9*9 乘法表 for(int i = 1; i < 10; i++){ for(int j = 1; j <= i; j++){ System.out.print(j + "*" + i + "=" + (i * j)+ "\t"); } System.out.println(); } */ /**输出水仙花数 如 153 = 1*1*1+5*5*5+3*3*3 int temp ; for(int i = 1; i <= 9;i++){ for(int j = 0; j <= 9;j++){ for(int x = 0;x <= 9;x++){ temp = i * 100 + j * 10 + x * 1; if(temp == i * i * i + j * j * j+ x * x * x){ System.out.println(temp); } } } } */ /** for(int i = 0;i < 5; i++){ System.out.println(i); if(i == 3){ //break;//跳出本层循环 //continue;//跳过本次循环,开始下次循环 return; //直接退出函数 } System.out.println(i); } System.out.println(132);*/ /**书本 P72 * 5、完成输入月份和年份,计算指定年份中的天数 Scanner sc = new Scanner(System.in); Scanner a = new Scanner(System.in); System.out.print("请输入年份:"); int year = sc.nextInt(); //System.out.println(year); System.out.print("请输入月份:"); int month = a.nextInt(); //System.out.println(month); if(year % 4 == 0 || year % 400 ==0){ System.out.println(year+"的天数是:" + "366" ); switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: System.out.println(year+"年份" + month + "月份的天数是"+ 31 +"天"); break; case 2: System.out.println(year+"年份" + month + "月份的天数是"+ 28 +"天"); break; default : System.out.println(year+"年份" + month + "月份的天数是"+ 30 +"天"); } } else{ System.out.println(year+"的天数是:" + "365" +"天"); switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: System.out.println(year+"年份" + month + "月份的天数是"+ 31 +"天"); break; case 2: System.out.println(year+"年份" + month + "月份的天数是"+ 29 +"天"); break; default : System.out.println(year+"年份" + month + "月份的天数是"+ 30 +"天"); } } */ /** * 6、完成将阿拉伯数字0-9转换为对应的中文字 零至九*/ int i; for(i = 0;i < 10;i++){ switch(i){ case 0: System.out.print("零"); break; case 1: System.out.print("一"); break; case 2: System.out.print("二"); break; case 3: System.out.print("三"); break; case 4: System.out.print("四"); break; case 5: System.out.print("五"); break; case 6: System.out.print("六"); break; case 7: System.out.print("七"); break; case 8: System.out.print("八"); break; case 9: System.out.print("九"); break; } } } }
