Read Integer in Java

-2

I have an exercise in Java where the program should read two numbers typed by the user and he should tell me which one is the greatest!

In this case, you can not use only IF , right? Should I also use ELSE ? Yes they are exercises of DESVIO DE CONDICIONAL

    
asked by anonymous 02.06.2018 / 01:23

1 answer

2

You can do this:

import java.util.Scanner;
public static void main(String[] args) 
{
 Scanner entrada = new Scanner(System.in);
 int a,b;

System.out.println("A :");
     a=entrada.nextInt;
System.out.println("B :");
     b=entrada.nextInt;
 if(a>b)
{
       System.out.println("A é maior com valor:"+a);
}else if(b>a)
{
       System.out.println("B é maior com valor:"+b);
}else
{
      System.out.println("Os números são iguais com valor:"+a);
}

}

First insert the two numbers and after the entry, compare using if, else if and else ...

    
02.06.2018 / 15:11