0
I am making a program that calculates BMI, using methods without Return. Programme in question:
package pct;
import java.util.Scanner;
public class Ex02Metodos {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
String sexo;
double altura, peso, valorIMC = 0;
System.out.println("Digite sua altura:");
altura = teclado.nextDouble();
System.out.println("Digite seu peso");
peso = teclado.nextDouble();
teclado.nextLine();
System.out.println("\n\nDigite seu sexo:");
sexo = teclado.nextLine();
calcularimc(altura,peso,valorIMC,sexo);
}
public static void calcularimc(double altura, double peso, double valorIMC, String sexo){
valorIMC = peso / (altura * altura);
if(sexo == "mulher"){
if(valorIMC < 19.1){
System.out.println("Abaixo do peso");
}
else if(valorIMC == 19.1 & valorIMC <= 25.8 ){
System.out.println("Peso normal");
}
else if(valorIMC == 25.8 & valorIMC <= 27.3){
System.out.println("Marginalmente acima do peso");
}
else if(valorIMC == 27.3 & valorIMC <= 31.1){
System.out.println("Acima do peso ideal");
}
else if(valorIMC > 31.1){
System.out.println("Obeso");
}
}
else if(sexo =="homem"){
if(valorIMC < 20.7){
System.out.println("Abaixo do peso");
}
else if(valorIMC == 20.7 & valorIMC <=26.4){
System.out.println("Peso normal");
}
else if(valorIMC == 26.4 & valorIMC <= 27.8){
System.out.println("Marginalmente acima do peso");
}
else if(valorIMC == 27.8 & valorIMC <= 32.3){
System.out.println("Acima do peso ideal");
}
else if(valorIMC > 32.3){
System.out.println("Obeso");
}
}
}
}
At the time of executing, is not running the method, it closes.
You tried to remove the
public static void main()
from within the scope of the class and rotate again?– Leonardo Pessoa
How do you know he’s not running the method
calcularimc
?– igventurelli
Forgive my lack of knowledge on the subject, but how do I know? Why did not print anything on the screen after the input question still in the main method. The program ended as soon as asked for input on user sex.
– zHardy
The method is running yes, it’s just not going through if Else. I just don’t know why yet.
– Edson F.
Ta working normally.
– user28595
Yeah, it looks like if Else isn’t working.
– zHardy