Java If statement practice

Source: Internet
Author: User

First question: finding the root of a two-second equation

public class Lianxi1 {

public static void main (string[] Args) {

System.out.println ("please Enter a value");
Scanner sc = new Scanner (system.in);
String A=sc.nextline ();
int x = Integer.parseint (a);
If (x!=0)
{
System.out.println ("please Enter the value of b");
Scanner SC1 =new Scanner (system.in);
System.out.println ("please Enter the value of c");
Scanner SC2 =new Scanner (system.in);
String B=sc1.nextline ();
String C=sc2.nextline ();
int y=integer.parseint (b), Z=integer.parseint (c), zhong=y*y-4*x*z;
Double i= (-y+math.sqrt (zhong))/(2*x), j= (-y+math.sqrt (zhong))/(2*x);

If (zhong<0) {
System.out.println ("the equation does not have a real root");
}
else if (zhong==0) {
System.out.println ("the equation has an identical real number root:" +i);
}
else{
System.out.println ("the equation has two distinct real roots:" +i+ "," +j ");
}
}

}

}

Second Question: enter a year to determine the horizontal leap years

public class Lianxi1 {

public static void main (string[] Args) {

System.out.println ("please Enter a year");
Scanner sc = new Scanner (system.in);
String a =sc.nextline ();
int X=integer.parseint (a);
If (x%400==0 | | x%4==0&&x%100!=0) {
System.out.println (a + "years is a leap year");
}
Else
{
System.out.println (a + "year is common year");
}
}

}

The third question: enter three number comparison size, output the largest number

public class Lianxi1 {

public static void main (string[] Args) {

System.out.println ("please enter");
Scanner sc = new Scanner (system.in);
String X=sc.nextline ();
String Y=sc.nextline ();
String Z=sc.nextline ();
Double a=double.parsedouble (x);
Double b=double.parsedouble (y);
Double c=double.parsedouble (z);
If (a>b) {
If (a>c) {
System.out.println (a);
}
Else
{
System.out.println (c);
}
}
Else
{
If (b>c) {
System.out.println (b);
}
Else
{
System.out.println (c);
}

}

}

}

Question Fourth: Enter gender, height, weight, figure

public class Lianxi1 {

public static void main (string[] Args) {

System.out.println ("please Enter your gender");
Scanner sc1=new Scanner (system.in);
String Sex=sc1.nextline ();
If (sex.equals ("male"))
{
System.out.println ("please Enter your height");
Scanner sc2=new Scanner (system.in);
String A=sc2.nextline ();

System.out.println ("please Enter your weight");
Scanner sc3=new Scanner (system.in);
String B=sc3.nextline ();
Double gao=double.parsedouble (a), zhong=double.parsedouble (b), bz=gao-100;
If (bz-zhong>=-3 && bz-zhong<=3) {
System.out.println ("you are the standard weight");
}
else if (bz-zhong<-3) {
System.out.println ("you are overweight");
}
else{
System.out.println ("you are thin");
}

}
else if (sex.equals ("female"))
{
System.out.println ("please Enter your height");
Scanner sc2=new Scanner (system.in);
String A=sc2.nextline ();

System.out.println ("please Enter your weight");
Scanner sc3=new Scanner (system.in);
String B=sc3.nextline ();
Double gao=double.parsedouble (a), zhong=double.parsedouble (b), bz=gao-110;
If (bz-zhong>=-3 && bz-zhong<=3) {
System.out.println ("you are the standard weight");
}
else if (bz-zhong<-3) {
System.out.println ("you are overweight");
}
else{
System.out.println ("you are thin");
}
}
Else
{
System.out.println ("are you a man or a Woman?") ");
}

}

}

Java If statement practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.