1. Enter a year, it is determined is not a leap year (but not divisible by four divisible by 100, or divisible by 400)
1 package tset; 2 import java.util.Scanner; 3 public class demo { 4 5 public static void main(String[] args) { 6 Scanner input = new Scanner(System.in); 7 System.out.println("请输入年份:"); 8 int a = input.nextInt(); 9 if (a % 4 == 0 && a % 100 != 0 || a % 400 ==0) { 10 System.out.println("是闰年"); 11 } else { 12 System.out.println ( "not a leap year" ); 13 is } 14 // the TODO Auto-Generated Method Stub 15 16 } . 17 18 is }
2. Enter a 4-digit card number, if one hundred number is a multiple of three, then the output is fortunate members, otherwise it is not output.
. 1 Package Tset; 2 Import java.util.Scanner; . 3 public class Demo { . 4 public static void main (String [] args) { . 5 Scanner INPUT = new new Scanner (the System.in); . 6 System.out.println ( "Please four input membership number: " ); . 7 int A = input.nextInt (); . 8 IF ((A% 1000/100)%. 3 == 0 ) { . 9 System.out.println (" lucky member " ); 10 } the else { . 11 System.out.println ( "not lucky member" ); 12 is } 13 is // the TODO Auto-Generated Method Stub 14 15 } 16 . 17 }
3. The value of the function is known, the value of the input x, output y of the corresponding.
X. 3 + (x> 0)
y = 0 (x = 0)
X2 -1 (x <0)
. 1 Package Tset; 2 Import java.util.Scanner; . 3 public class Demo { . 4 public static void main (String [] args) { . 5 Scanner INPUT = new new Scanner (the System.in); . 6 System.out.println ( "Please the input value x (integer): " ); . 7 int x = input.nextInt (); . 8 int Y; . 9 IF (x> 0 ) { 10 Y = x +. 3 ; . 11 System.out.println (" Y is values are: "+ Y); 12 is } The else IF (X == 0 ) { 13 is System.out.println ( "value of y is: 0" ); 14 } the else IF (X <0 ) { 15 y = X * X -. 1 ; 16 the System.out .println ( "value of y is:" + y); . 17 } 18 is . 19 } 20 is 21 is }
4. Enter the number of three, determines whether a triangular configuration (the sum of any two sides is greater than the third side)
. 1 Package Tset; 2 Import java.util.Scanner; . 3 public class Demo { . 4 public static void main (String [] args) { . 5 Scanner INPUT = new new Scanner (the System.in); . 6 System.out.println ( "Please three sides of the triangle input (integer): " ); . 7 int a = input.nextInt (); . 8 int B = input.nextInt (); . 9 int C = input.nextInt (); 10 int D = a + B; 11 int= A + E C; 12 is int F = B + C; 13 is IF (D> C && E> F && B> A) { 14 System.out.println ( "can form a triangle" ); 15 } the else { 16 the System .out.println ( "not constitute a triangle" ); 17 } 18 } 19 }