Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Kneel down and ask java experts to help me see what's wrong with my program. If I correct it, I will add 20 points.
Kneel down and ask java experts to help me see what's wrong with my program. If I correct it, I will add 20 points.
This is the for(I = height; I> 1; I-); This statement is wrong. You should take decimal places. But when you write this statement, you should forget that if i= 1, this statement will also be suspended, and when calculating weight = (I *10+l *12) * 5+100, it will cause (/kloc-0. For example, when you enter 6, the original output result is 160 pounds, and the resulting output is 2 10 pounds.

All you have to do is change the program to this.

Import java.util.scanner;

Public category weight {

/**

* @param args

*/

Public static void main(String[] args) {

// TODO automatically generated method stub

String str

char st

Scanner scan = new scanner (system. in);

System.out.print ("Please enter your gender (F or M):");

str = scan . nextline();

ST = str . charat(0);

if(st=='F'||st=='f ')

{

Float i, height, weight, k, l = 0;;

System.out.print ("Please enter your height (height & gt=5):");

height = scan . next float();

If (height & gt5)

{

For(I = height; I>= 1; I-);

For(k=(int) height; k & gt5; k-)l++;

Weight = (I *10+l *12) * 5+100;

System. out.print ("weight ="+weight+"points." );

}

Elseif (height = = 5) system. out.print ("weight =100lb");

Else System.out.print ("error ...");

}

else if(st=='M'||st=='m ')

{

Float i, height, weight, k, l = 0;;

System.out.print ("Please enter your height (height & gt=6):");

height = scan . next float();

If (height & gt5)

{

For(I = height; I>= 1; I-);

For(k=(int) height; k & gt5; k-)l++;

Weight = (I *10+l *12) * 6+106;

System. out.print ("weight ="+weight+"pound");

}

Elseif (height = = 5) system. out.print ("weight =106 lb");

Else System.out.print ("error ...");

}

Else System.out.print ("error ...");

}

}