What’s the mistake in that code?

Asked

Viewed 72 times

-4

I did not understand what the error of the code.

import java.util.Scanner;

public class Questao4 {
   public static void main (String[] args){
      Scanner scanner = new Scanner(System.in);
      double Altura, Fixo, Fixo2, PesoIdeal, Resultado1;

      Altura = 1,73; //Chute
      Fixo = 72,7;
      Fixo2 = 58;

      Resultado1 = Altura * Fixo;
      PesoIdeal = Resultado1 - Fixo2;

      System.out.print("Peso Ideal = " + PesoIdeal);
   }
}

When compiling, the following errors were detected:

Questao4.java:6: error: ';' expected
    Altura = 1,73; //Chute
Questao4.java:7: error: ';' expected
    Fixo = 72,7;
  • 4

    In java. Double numbers have to be point (e.g. 1.73) and not comma (1.73)

  • 2

    I found the negative votes exaggerated, I think the comment of @adventistaam solve the problem

  • 1

    Before the issue, the votes are deserved yes. Reason for closure was mistaken, I think this is more typo.

1 answer

2


Floating point numbers are separated with a decimal point, not a decimal point.

Moreover, variable names should start with lowercase letters, although the compiler won’t complain about it, it’s just a code convention.

Your corrected code:

import java.util.Scanner;

public class Questao4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        double altura = 1.73; //Chute
        double fixo = 72.7;
        double fixo2 = 58;

        double resultado1 = altura * fixo;
        double pesoIdeal = resultado1 - fixo2;

        System.out.print("Peso Ideal = " + pesoIdeal);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.