Read Java Integer Number

Asked

Viewed 692 times

-2

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

Then there’s no way I can just use IF right? I should also use the ELSE ? Yes are exercises of DESVIO DE CONDICIONAL

  • With a if..else you can solve the exercise.

  • 1

    our what my head I forgot of if! Thank you

  • Hi @Carolm posted the code, I hope I helped!

1 answer

2


You can do it like 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 input, compare using if, Else if and Else...

Browser other questions tagged

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