1、编写一个控制台程序,输入一个日期,求下一天的日期。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int month;
int year;
int day;
System.out.println("请输入年份,月份,日期");
year = s.nextInt();
month = s.nextInt();
day = s.nextInt();
check(year,month,day);
}
public static void check(int y , int m , int d) {
switch(m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:if(d+1 > 31) {
m++;
d=1;
}
else
d++;
break;
case 4:
case 6:
case 9:
case 11:if(d+1 > 30) {
m++;
d=1;
}
else
d++;
break;
case 12:if(d+1 > 31) {
y++;
m=1;
d=1;
}
else
d++;
break;
case 2:if(y%4==0 && y%100!=0 || y%400==0) {
if(d+1>29) {
m++;
d=1;
}
else
d++;
}
else {
if(d+1 > 28) {
m++;
d=1;
}
else
d++;
}
break;
}
System.out.println("下一天为"+y+"年"+m+"月"+d+"日");
}
}
———————————————————————————————————————————
2、编写函数,实现一维及二维数组的复制,并输出复制后的数组
import java.util.Scanner;
public class Main2 {
static Scanner s=new Scanner(System.in);
public static void main(String[] args) {
int t;
System.out.println("复制一维数组请按1,复制二维数组请按2");
t = s.nextInt();
if(t==1) {
int one1;
System.out.println("请输入数组长度");
one1 = s.nextInt();
int cone[] = copyone(one1);
System.out.print("复制成功:");
for(int i=0; i<one1 ;i++) {
System.out.print(cone[i]+" ");
}
}
if(t==2) {
int two1;
int two2;
int k = 0;
System.out.println("请输入一维长度和二维长度");
two1 = s.nextInt();
two2 = s.nextInt();
int ctwo[][] = copytwo(two1,two2);
System.out.print("复制成功:");
for(int i=0 ;i<two1 ;i++) {
for(int j=0 ;j<two2 ;j++) {
if(k % two1 == 0)
System.out.println();
System.out.print(ctwo[i][j]+" ");
k++;
}
}
}
}
public static int[] copyone(int n) {
//System.out.println("执行copyone");
int one[] = new int[n];
System.out.println("请输入数组元素");
for(int i=0;i<n;i++) {
one[i] = s.nextInt();
}
return one;
}
public static int[][] copytwo(int m,int n){
//System.out.println("执行coppytwo");
int two[][]=new int[m][n];
System.out.println("请输入数组元素");
for(int i=0 ;i<m ;i++) {
for(int j=0 ;j<n ;j++) {
two[i][j]=s.nextInt();
}
}
return two;
}
}