1.一个星期的运动安排:输入周几输出运动项目
package javalearn;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("输入星期数:");
int week1=sc.nextInt();
sports(week1);
}
public static void sports(int week){
if(week<1||week>7){
System.out.println("输入有误");
} else if(week==1){System.out.println("Running");}
else if(week==2){System.out.println("swimming");}
else if(week==3){System.out.println("jogging");}
else if(week==4){System.out.println("hiking");}
else if(week==5){System.out.println("riding");}
else if(week==6){System.out.println("climbing");}
else {System.out.println("eating");}
}
}
2.1-100的逢七过
package javalearn;
public class Test2 {
public static void main(String[] args){
for (int i=1;i<101;i++){
cal(i);
}
}
public static void cal(int num){
if(num%7==0||num%10==7||num/10%10==7){
System.out.println("pass");
}else{
System.out.println(num);
}
}
}
3.兔子:一对兔子从出生后三个月期每月都生一对兔子,小兔子也符合这一规律,问第二十个月有多少对兔子
package javalearn;
public class Test3 {
public static void main(String[] args) {
int[] arr = new int[20];
arr[0] = 1;
arr[1] = 1;
for (int i = 2; i < 20; i++) {
arr[i]=arr[i-1]+arr[i-2];
}
System.out.println(arr[19]);
}
}