Struggling on if else statement
up vote
0
down vote
favorite
I am very curious about the else and if statement.
Why mine is not working like this..I can't find anyway to correct it anymore but it just won't run and show an error which is else without if.
import java.util.Scanner;
public class Q2Prac5Extra
public static void main(String args)
final float x=0.0254f;
float height , weight;
int age;
String gender;
System.out.print("************Ideal Weight Calculator************nnPlease enter your gender: ");
gender = input.nextLine();
System.out.print("Please enter your height: ");
height = input.nextFloat();
System.out.print("Please enter your age: ");
age = input.nextInt();
if(age<18)
System.out.print("bye");
else if (height<1.22);
System.out.print("bye bye bye");
else
if(gender.equals("male"))
weight = 29.2f + 1.9f*((height-1.22f)/x);
else
weight = 28.6f + 1.7f*((height-1.22f)/x);
System.out.print("nnThe ideal weight of this person is " + String.format("%.0f",weight) + "kgnn");
jcreator
add a comment |
up vote
0
down vote
favorite
I am very curious about the else and if statement.
Why mine is not working like this..I can't find anyway to correct it anymore but it just won't run and show an error which is else without if.
import java.util.Scanner;
public class Q2Prac5Extra
public static void main(String args)
final float x=0.0254f;
float height , weight;
int age;
String gender;
System.out.print("************Ideal Weight Calculator************nnPlease enter your gender: ");
gender = input.nextLine();
System.out.print("Please enter your height: ");
height = input.nextFloat();
System.out.print("Please enter your age: ");
age = input.nextInt();
if(age<18)
System.out.print("bye");
else if (height<1.22);
System.out.print("bye bye bye");
else
if(gender.equals("male"))
weight = 29.2f + 1.9f*((height-1.22f)/x);
else
weight = 28.6f + 1.7f*((height-1.22f)/x);
System.out.print("nnThe ideal weight of this person is " + String.format("%.0f",weight) + "kgnn");
jcreator
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am very curious about the else and if statement.
Why mine is not working like this..I can't find anyway to correct it anymore but it just won't run and show an error which is else without if.
import java.util.Scanner;
public class Q2Prac5Extra
public static void main(String args)
final float x=0.0254f;
float height , weight;
int age;
String gender;
System.out.print("************Ideal Weight Calculator************nnPlease enter your gender: ");
gender = input.nextLine();
System.out.print("Please enter your height: ");
height = input.nextFloat();
System.out.print("Please enter your age: ");
age = input.nextInt();
if(age<18)
System.out.print("bye");
else if (height<1.22);
System.out.print("bye bye bye");
else
if(gender.equals("male"))
weight = 29.2f + 1.9f*((height-1.22f)/x);
else
weight = 28.6f + 1.7f*((height-1.22f)/x);
System.out.print("nnThe ideal weight of this person is " + String.format("%.0f",weight) + "kgnn");
jcreator
I am very curious about the else and if statement.
Why mine is not working like this..I can't find anyway to correct it anymore but it just won't run and show an error which is else without if.
import java.util.Scanner;
public class Q2Prac5Extra
public static void main(String args)
final float x=0.0254f;
float height , weight;
int age;
String gender;
System.out.print("************Ideal Weight Calculator************nnPlease enter your gender: ");
gender = input.nextLine();
System.out.print("Please enter your height: ");
height = input.nextFloat();
System.out.print("Please enter your age: ");
age = input.nextInt();
if(age<18)
System.out.print("bye");
else if (height<1.22);
System.out.print("bye bye bye");
else
if(gender.equals("male"))
weight = 29.2f + 1.9f*((height-1.22f)/x);
else
weight = 28.6f + 1.7f*((height-1.22f)/x);
System.out.print("nnThe ideal weight of this person is " + String.format("%.0f",weight) + "kgnn");
jcreator
jcreator
asked Nov 8 at 22:08
Shang Huang
33
33
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216891%2fstruggling-on-if-else-statement%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown