第三次作业
1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)
package threehomework; import java.util.Scanner; public class text1 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.println("请输入一个年份"); int year = input.nextInt(); if (year % 4 == 0 || year % 400 == 0 && year % 100 != 0 ) { System.out.println("此年份是闰年"); }else { System.out.println("此年份不是闰年"); } } }
2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是.
package threehomework; import java.util.Scanner; public class text1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入一个四位数的会员卡号"); int number = input.nextInt(); int bai = number % 1000 / 100 ; if (bai % 3 == 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 threehomework; import java.util.Scanner; public class text1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入一个X的值"); int X = input.nextInt(); 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=" + (2*X-1)); }else { System.out.println("无结果"); } } }
4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)
package threehomework; import java.util.Scanner; public class text1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入第一个数"); int a = input.nextInt(); System.out.println("请输入第二个数"); int b = input.nextInt(); System.out.println("请输入第三个数"); int c = input.nextInt(); if (a+b>c && b+c>a && a+c>b) { System.out.println("这三位数可构成三角形"); }else { System.out.println("这三个数不可构成三角形"); } } }