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