码迷,mamicode.com
首页 > 其他好文 > 详细

实验二

时间:2014-10-03 20:51:45      阅读:365      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!