标签:style blog color io ar java for sp div
1.编写Java Application程序,输出1900年到2000年之间的所有润年。(闰年的判断条件:能被4整除且不能被100整除,或能被400整除);
public class RunNian { public static void main(String[] args){ for(int i = 1900; i<= 2000; i++){ if((i % 4 == 0 && i % 100 !=0)||i % 400 ==0){ System.out.println("i = " + i); } } } }
2. 金字塔:Pyramid.java
在屏幕上显示一个由星型符号“*”组成的金字塔图案,示例如下:
*
***
*****
*******
要求:金字塔高度h,可以由用户设置。
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Ta { public static void main(String[] args) throws IOException{ BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); System.out.println("输入想要的高度:"); String str=buf.readLine(); int maxLength=Integer.parseInt(str); for(int m = 1; m <= maxLength; m++){ printBlanks(maxLength - m); printStar(2 * m - 1); System.out.println(); } } public static void printStar(int n){ for(int i = 0; i < n; i++){ System.out.print("*"); } } public static void printBlanks(int n){ for(int i = 0; i < n; i++){ System.out.print(" "); } } }
标签:style blog color io ar java for sp div
原文地址:http://www.cnblogs.com/lcpholdon/p/4005222.html