1. Solution of a two-dimensional equation
Note: The root formula is (-b+ radical Delta)/2a, (-b-)/2a
Scanner sc=new Scanner (system.in); SYSTEM.OUT.PRINTLN ("Input A:");d ouble a=sc.nextfloat (); SYSTEM.OUT.PRINTLN ("Input B:");d ouble b=sc.nextfloat (); SYSTEM.OUT.PRINTLN ("Input C:");d ouble c=sc.nextfloat ();d ouble delta=b*b-4*a*c,x1,x2;if (delta>0) {x1= (-b+math.sqrt ( Delta)/(2*A); x2= (-b-math.sqrt (Delta))/(2*A); System.out.println ("real roots of the equation: x1=" +x1+ "," + "x2=" +x2 ");} else if (delta==0) {x1= (-b+math.sqrt (Delta))/(2*a); x2=x1; System.out.println ("The real roots of the equation is: x1=x2=" +x1);} else if (delta<0) {System.out.println ("Equation without real Roots");}
2. Judging leap years
Note: A leap year is one that can be divisible by 400 or divisible by 4 and not divisible by 100.
System.out.println ("Enter a year"); Scanner sc=new Scanner (system.in); long A=sc.nextlong (); if (a%400==0) {System.out.println ("Leap Year");} else if (a%4==0&&a%100!=0) {System.out.println ("Leap Year");} else {System.out.println ("Common Year");}
3. Judging whether it is a standard weight
Note:
The meaning of the standard body weight: Height-weight (kg) and 100 (110) Subtract, the difference is more than 3 is thin, less than 3 is overweight, between 3 and 3 is the standard.
Scanner sc=new Scanner (system.in); System.out.println ("Please enter gender (male or female):"); String Sex=sc.next (); System.out.println ("Please enter height:"); int height=sc.nextint (); System.out.println ("Please enter weight (kg):"), int weight=sc.nextint (), int a=height-weight;if (sex.equals ("male")) {if (a-100>=-3 &&a-100<=3) {System.out.println ("standard Weight");} else if (a-100>3) {System.out.println ("fat");} else if (a-100<3) {System.out.println ("lean");}} else if (sex.equals ("female")) {if (a-110>=-3&&a-110<=3) {System.out.println ("standard Weight");} else if (a-110>3) {System.out.println ("fat");} else if (a-110<-3) {System.out.println ("lean");}}
4. Three number of maximum values
System.out.println ("Enter three numbers:"); Scanner sc=new Scanner (system.in); System.out.println ("Enter the first number"); Long A=sc.nextlong (); System.out.println ("Enter a second number"); Long B=sc.nextlong (); System.out.println ("Enter a third number"); Long C=sc.nextlong (); Long big=a>b?a:b;big=big>c?big:c; System.out.println ("The largest number is:" +big);
Java Practice Questions: solving a two-time equation, judging leap years, judging the standard body, three numbers to take the maximum value