java第四次作业
package test; import java.util.Scanner; public class test1 { /** * @param args */ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("输入一个年份"); int year=input.nextInt(); if (year%4==0&&year%100!=0||year%400==0) { System.out.println(year+"是闰年"); } else { System.out.println(year+"不是闰年"); } } }
package test; import java.util.Random; import java.util.Scanner; public class test2 { public static void main(String[] args) { System.out.println("请输入卡号"); Scanner input=new Scanner(System.in); int h=input.nextInt(); int x; x=h/100%10; Random r=new Random(); int s=r.nextInt(10); System.out.println(s); if (x==s) { System.out.println("是幸运会员"); } else { System.out.println("不是幸运会员"); } } }
package test; import java.util.Scanner; public class test2 { /** * @param args */ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("输入一个数"); int x=input.nextInt(); int y; if(x>0){ y=x+3; System.out.println("y="+y); }else if(x==0){ y=0; System.out.println("y="+y); }else{ y=x*2-1; System.out.println("y="+y); } } }
package test; import java.util.Scanner; public class test4 { /** * @param args */ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("输入第一条边"); int a=input.nextInt(); System.out.println("输入第二条边"); int b=input.nextInt(); System.out.println("输入第三条边"); int c=input.nextInt(); if (a+b>c||a+c>b||b+c>a) { System.out.println("是三角形"); } else { System.out.println("不是三角形"); } } }
作业:
package test; import java.util.Scanner; public class task1 { public static void main(String[] args) { System.out.println("请输入年份"); Scanner input=new Scanner(System.in); int year=input.nextInt(); System.out.println("请输入月份"); int month=input.nextInt(); int day; if (((year%4==0&&year%100!=0)||year%400==0)&&month==2) { day=29; System.out.println("该月的天数为"+day); } else if(month==1) { day=31; System.out.println("该月的天数为"+day); }else if(month==2) { day=28; System.out.println("该月的天数为"+day); }else if(month==3) { day=31; System.out.println("该月的天数为"+day); }else if(month==4) { day=30; System.out.println("该月的天数为"+day); }else if(month==5) { day=31; System.out.println("该月的天数为"+day); }else if(month==6) { day=30; System.out.println("该月的天数为"+day); }else if(month==7) { day=31; System.out.println("该月的天数为"+day); }else if(month==8) { day=31; System.out.println("该月的天数为"+day); }else if(month==9) { day=30; System.out.println("该月的天数为"+day); }else if(month==10) { day=31; System.out.println("该月的天数为"+day); }else if(month==11) { day=30; System.out.println("该月的天数为"+day); }else if(month==12) { day=31; System.out.println("该月的天数为"+day); } } }
package test; import java.util.Scanner; public class task2 { public static void main(String[] args) { System.out.println("请输入一个成绩"); Scanner input=new Scanner(System.in); int chengji=input.nextInt(); switch (chengji/10) { case 10: System.out.println("成绩的等级为A"); break; case 9: System.out.println("成绩的等级为A"); break; case 8: System.out.println("成绩的等级为B"); break; case 7: System.out.println("成绩的等级为C"); break; case 6: System.out.println("成绩的等级为D"); break; default: System.out.println("成绩的等级为E"); break; } } }
package test; import java.util.Scanner; public class task3 { public static void main(String[] args) { System.out.println("请输入一个数"); Scanner input=new Scanner(System.in); int num=input.nextInt(); if (num%2==0) { System.out.println("此数是偶数"); } else { System.out.println("此数是奇数"); } } }
package test; import java.util.Scanner; public class task4 { public static void main(String[] args) { System.out.println("请输入一个变量x"); Scanner input=new Scanner(System.in); int x=input.nextInt(); if (x==1) { System.out.println("x=1"); } else if(x==5){ System.out.println("x=5"); }else if(x==10){ System.out.println("x=10"); }else{ System.out.println("x=none"); } } }
package test; import java.util.Scanner; public class task5 { public static void main(String[] args) { System.out.println("请输入一个数"); Scanner input=new Scanner(System.in); int a=input.nextInt(); if (a%5==0&&a%6==0) { System.out.println("此数能被5和6整除"); } else if(a%5==0) { System.out.println("此数能被5整除"); }else if(a%6==0) { System.out.println("此数能被6整除"); }else if(a%5!=0||a%6!=0) { System.out.println("此数不能被5或6整除"); } } }