编写一个java程序

2025-04-11 13:35:50
推荐回答(1个)
回答1:

/*
* Main.java
*
* Created on 2007年1月13日, 下午9:40
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package know;

/**
*
* @author Administrator
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
int year = 1800 + (int)(Math.random() * 200);
if(year % 4 == 0){
if(year % 100 == 0){
if(year % 400 == 0)
System.out.println("公元" + year + "是闰年!");
else
System.out.println("公元" + year + "不是闰年!");
}
else
System.out.println("公元" + year + "是闰年!");
}
else
System.out.println("公元" + year + "不是闰年!");
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main();// TODO code application logic here
}

}
/*
* Question2.java
*
* Created on 2007年1月13日, 下午9:47
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package know;

/**
*
* @author Administrator
*/
public class Question2 {

/** Creates a new instance of Question2 */
public Question2() {
int length = 2000;
int n = 0;
while(length >= 5){
length /= 2;
n ++;
}
System.out.println(n + "天后长度小于5米");
}

public static void main(String[] args) {
new Question2();
}
}
/*
* Question3.java
*
* Created on 2007年1月13日, 下午9:54
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package know;

/**
*
* @author Administrator
*/
public class Question3 {

/** Creates a new instance of Question3 */
public Question3() {
int[] intArray = new int[10];
System.out.println("随机的10个数是");
for(int i = 0;i < 10;i++){
intArray[i] = (int)(Math.random() * 99);
System.out.print(intArray[i] + " ");
}
System.out.println(" ");
int max = intArray[0];
int min = intArray[0];
for(int i = 0;i < 10;i++){
if(max <= intArray[i])
max = intArray[i];
if(min >= intArray[i])
min = intArray[i];
}
System.out.println("最大的是:" + max);
System.out.println("最小的是:" + min);
}

public static void main(String[] args) {
new Question3();
}
}