Java实验八 综合实验及练习
第一部分:编程题
1、编写程序实现输入整数n,输出如下所示由数字组成的菱形。(图中n=5) 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1
package ex8_1; public class Demo { }
public static void main(String[] args){ }
for(int i=1;i<6;i++){ }
for(int i=4;i>0;i--){ }
for(int j=1;j<=i;j++)
System.out.printf(\,j); System.out.printf(\,j); for(int j=i-1;j>0;j--) System.out.println(); for(int j=1;j<=i;j++)
System.out.printf(\,j); System.out.printf(\,j); for(int j=i-1;j>0;j--) System.out.println();
2.给出年、月、日,计算该日是该年的第几天?
package ex8_2;
import java.util.Scanner; public class DateFun {
public static boolean YearDemo(int year){
boolean flage=true;
if((year%4==0&&year0!=0)||year@0==0)
flage=true; else flage=false; return flage;
}
}
public static void main(String[] args){ }
Scanner scan=new Scanner(System.in); System.out.println(\请输入年月日\); int sum=0;int year;int month; int day; year=scan.nextInt(); month=scan.nextInt(); day=scan.nextInt(); if(YearDemo(year)){ } else { }
int [] days={31,28,31,30,31,30,31,31,30,31,30,31}; for(int i=1;i sum+=days[i-1]; sum+=day; System.out.println(\该日是当年的\+sum+\天\); int [] days={31,29,31,30,31,30,31,31,30,31,30,31}; for(int i=1;i sum+=days[i-1]; sum+=day; System.out.println(\该日是当年的\+sum+\天\); 3、利用求素数的方法,就6~2000000之间的所有偶数验证歌德巴赫猜想: 任何一个大于6的偶数可以分解为两个素数之和。 package ex8_3; import java.util.Scanner; public class Gede { public static boolean Demo(int a){