1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)
1 package text; 2 import java.util.Scanner; 3 4 public class note1 { 5 public static void main(String[] args) { 6 Scanner input = new Scanner(System.in); 7 System.out.println("输入一个年份"); 8 int year = input.nextInt(); 9 if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { 10 System.out.println(year + "是闰年"); 11 } else { 12 System.out.println(year + "不是闰年"); 13 } 14 15 } 16 17 }
2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是.
1 package text; 2 import java.util.Scanner; 3 4 public class note1 { 5 public static void main(String[] args) { 6 Scanner input = new Scanner(System.in); 7 System.out.println("输入一个4位会员卡号:"); 8 int card = input.nextInt(); 9 int bai = card / 100 % 10; 10 if(card > 9999 || card < 1000){ 11 System.out.println("会员卡号错误"); 12 }else if(bai % 3 == 0){ 13 System.out.println(card + "是幸运会员"); 14 }else{ 15 System.out.println("不是幸运会员"); 16 } 17 18 } 19 20 }
3.已知函数,输入x的值,输出对应的y的值.
x + 3 ( x > 0 )
y = 0 ( x = 0 )
x2 –1 ( x < 0 )
1 package text; 2 import java.util.Scanner; 3 4 public class note1 { 5 public static void main(String[] args) { 6 Scanner input = new Scanner(System.in); 7 System.out.println("输入一个x值:"); 8 double x = input.nextDouble(); 9 if (x > 0) { 10 System.out.println("y =" + (x + 3)); 11 } else if(x == 0){ 12 System.out.println("y =" + x); 13 }else{ 14 System.out.println("y =" + (x * 2 - 1)); 15 } 16 17 } 18 }
4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)
1 package text; 2 import java.util.Scanner; 3 4 public class note1 { 5 public static void main(String[] args) { 6 Scanner input = new Scanner(System.in); 7 System.out.println("输入三角形三条边:"); 8 int a = input.nextInt(); 9 int b = input.nextInt(); 10 int c = input.nextInt(); 11 if ((a+b)>c&&(a+c)>b&&(b+c)>a) { 12 System.out.println("可以构成三角形"); 13 }else{ 14 System.out.println("不可以构成三角形"); 15 } 16 17 } 18 19 }