1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)
package finish; import java.util.Scanner; public class Zuoye4 { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("请输入月份"); int a=input.nextInt(); if(a%4==0&&a%100!=0||a%400==0) { System.out.println("是闰月"); } else { System.out.println("不是闰月"); } } }
2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是.
package finish; import java.util.Scanner; public class Zuoye5 { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("请输入四位会员卡号"); int a=input.nextInt(); switch(a%1000/100) { case 3: case 6: case 9: System.out.println("幸运会员");break; default: System.out.println("不是幸运会员");break; } } }
3.已知函数,输入x的值,输出对应的y的值.
x + 3 ( x > 0 )
y = 0 ( x = 0 )
x2 –1 ( x < 0 )
package finish; import java.util.Scanner; public class Zuoye6 { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("请输入x的值"); int x=input.nextInt(); int y; if(x>0) y=x+3; else if(x==0) y=0; else y=x*x-1; System.out.println("y的值是"+y); } }
4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)
package finish; import java.util.Scanner; public class Zuoye7 { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("请输入三个数"); int a=input.nextInt(); int b=input.nextInt(); int c=input.nextInt(); if(a+b>c&&a+c>b&&b+c>a) System.out.println("能够成三角形"); else System.out.println("不能构成三角形"); } }