第三周作业
package tx; import java.util.Scanner; public class test { public static void main(String[] args) { // TODO Auto-generated method stub; //1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除) 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("是闰年"); }else{ System.out.println("不是闰年"); } } }
package tx; import java.util.Scanner; public class test { public static void main(String[] args) { // TODO Auto-generated method stub; //2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是. Scanner input= new Scanner(System.in); System.out.println("请输入会员卡号"); int kh=input.nextInt(); int bw=kh/100%10; if(bw%3==0){ System.out.println("幸运会员"); }else{ System.out.println("不是幸运会员"); } } }
package tx; import java.util.Scanner; public class test { public static void main(String[] args) { // TODO Auto-generated method stub; //3.已知函数,输入x的值,输出对应的y的值. // x + 3 ( x > 0 ) // y = 0 ( x = 0 ) // x2 –1 ( x < 0 ) Scanner input= new Scanner(System.in); System.out.println("请输入x"); int x=input.nextInt(); int y; if(x>0){ System.out.println(y=x+3); }else if(x==0){ System.out.println(y=0); }else if(x<0){ System.out.println(y=x*x-1); } } }
package tx; import java.util.Scanner; public class test { public static void main(String[] args) { // TODO Auto-generated method stub; //4.输入三个数,判断能否构成三角形(任意两边之和大于第三边) Scanner input= new Scanner(System.in); System.out.println("请输入三个数"); int x=input.nextInt(); int y=input.nextInt(); int z=input.nextInt(); if(x+y>z&&x+z>y&&y+z>x){ System.out.println("构成三角形"); }else{ System.out.println("不能构成三角形"); } } }