Java第四次作业
package Class1; import java.util.Random; import java.util.Scanner; public class Class1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入您的卡号"); int num=input.nextInt(); int c; c=num/100%10; Random r=new Random(); int a=r.nextInt(10); System.out.println("今天的幸运数字是"+a); if(c==a){ System.out.println("恭喜您成为幸运会员"); } else{ System.out.println("谢谢惠顾"); } } }
package Class1; import java.util.Scanner; public class Class2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入年份"); int num=input.nextInt(); if (num%4==0&&num%100!=0||num%400==0) { System.out.println(num+"是闰年"); } else { System.out.println(num+"不是闰年"); } } }
package Class1; import java.util.Scanner; public class Class3 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入x的值"); 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 if(x<0){ y=2*x-1; } } }
package Class1; import java.util.Scanner; public class Class4 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入三角形的三条边"); System.out.println("请输入a"); int a=input.nextInt(); System.out.println("请输入b"); int b=input.nextInt(); System.out.println("请输入c"); int c=input.nextInt(); if (a+c>b&&b+a>c&&b+c>a) { System.out.println("能构成三角形"); } else{ System.out.println("不能构成三角形"); } } }
package Home4; import java.util.Scanner; public class Home4 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.println("请输入年份"); int year = input.nextInt(); System.out.println("请输入月份"); int month = input.nextInt(); if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { month = 31; } else if (month == 4 || month == 6 | month == 9 || month == 11) { month = 30; } else if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0 && month == 2) { System.out.println("该年为闰年"); month = 29; } else { month = 28; } System.out.println("该月份的天数为" + month); } }
package Class1; import java.util.Scanner; public class Class6 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入成绩"); int a=input.nextInt(); switch (a/10) { case 6: System.out.println("您的成绩等级为D"); break; case 7: System.out.println("您的成绩等级为C"); break; case 8: System.out.println("您的成绩等级为B"); break; case 9: case 10: System.out.println("您的成绩等级为A"); break; default: System.out.println("您的成绩等级为E"); break;} } }
package Class1; import java.util.Scanner; public class Class7 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个数字"); int a=input.nextInt(); if(a%2==0){ System.out.println("该数为偶数"); }else{ System.out.println("该数为奇数"); } } }
package Class1; import java.util.Scanner; public class Class8 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个数值X"); 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 Class1; import java.util.Scanner; public class Class9 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个数值X"); int x=input.nextInt(); if(x%5==0&&x%6==0){ System.out.println("能被5和6整除"); }else if(x%5==0){ System.out.println("只能被5整除"); }else if(x%6==0){ System.out.println("只能被6整除"); }else if(x%5!=0||x%6==0){ System.out.println("不能被5或6整除"); } } }
package Class1;
import java.util.Random;
import java.util.Scanner;
publicclass Class1 {
/**
* @param args
*/
publicstaticvoid main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("请输入您的卡号");
int num=input.nextInt();
int c;
c=num/100%10;
Random r=new Random();
int a=r.nextInt(10);
System.out.println("今天的幸运数字是"+a);
if(c==a){
System.out.println("恭喜您成为幸运会员");
}
else{
System.out.println("谢谢惠顾");
}
}
}