-4
import java.util.Scanner;

public class HelloWorldJavaMain 
{

    public static void main(String[] args) 
    {

        Scanner userInputScanner = new Scanner(System.in);

        System.out.println("Enter the first number.");
        int inputA = userInputScanner.nextLine();

        System.out.println("Enter the second number.");
        int inputB = userInputScanner.nextLine();

        int sumOfInputs = inputA + inputB;

        System.out.println(inputA + " + " + inputB  + " = " + sumOfInputs);

    }

}

Can someone tell me where I went wrong?

Hemerson Varela
  • 24,034
  • 16
  • 68
  • 69
  • 1
    int inputA = userInputScanner.nextLine(); – Madhawa Priyashantha Oct 16 '14 at 20:36
  • 1
    This won't even compile. If you try, you'll get an error message that will point you in the right direction. – dimo414 Oct 16 '14 at 20:38
  • thats what i wrote... – user3832004 Oct 16 '14 at 20:38
  • possible duplicate of [How to get basic user input for java](http://stackoverflow.com/questions/5287538/how-to-get-basic-user-input-for-java) – scrappedcola Oct 16 '14 at 20:38
  • 1
    Actually, you don't have any details other than "can someone where I went wrong". If you want actual help you need to provide details. Is it compiling? If not what errors and line numbers? Do you get wrong output? If so what do you expect vs what you are getting? These types of things. – scrappedcola Oct 16 '14 at 20:40
  • 2
    @user3832004 No, you didn't. In fact you haven't described the actual problem you're experiencing at all. As a general rule when posting on SO, you need to be specific about the problem or question you have. Explain where the error is occurring, what error messages you're receiving, unexpected versus expected behaviour, etc. Otherwise, you're asking somebody to pick through your code and perform the debugging that you yourself should have done originally. – Paul Richter Oct 16 '14 at 20:40

3 Answers3

1
int inputA = userInputScanner.nextLine();

should change to

int inputA = userInputScanner.nextInt();

because nextline doesn't return int .or you could use

Integer.parseInt(userInputScanner.nextLine())

same thing to inputB

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
0

Use userInputScanner.nextInt();

userInputScanner.nextLine() reads a String line.

Manish Maheshwari
  • 4,045
  • 2
  • 15
  • 25
0
Scanner userInputScanner = new Scanner(System.in);
int inputA = userInputScanner.nextInt();
int inputB = userInputScanner.nextInt();
int sumOfInputs = inputA + inputB;
System.out.println(inputA + " + " + inputB  + " = " + sumOfInputs);

check this http://ideone.com/0eR41r

Andres
  • 4,323
  • 7
  • 39
  • 53