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