Home > Back-end >  I'm not able to run Java program in IntelliJ IDEA Community Edition
I'm not able to run Java program in IntelliJ IDEA Community Edition

Time:08-03

I was able to run only statements in System.out.println. When I was trying to give user input during runtime, it's not asking me

enter image description here

Can anyone help please?

CodePudding user response:

There is just one line missing, you need to close the Scanner before you can reach your last System.out.println.

import java.util.Scanner;
public class Test {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.println("Enter two numbers:");
        int num1 = in.nextInt();
        int num2 = in.nextInt();
        int sum = num1   num2;
        in.close(); //This one is important
        System.out.println("The sum is : "   sum);
    }
}

Then you click into the console and type in your first int --> press Enter and the same for the second int

CodePudding user response:

as can be seen in your screenshot, your program runs and waits for your input, your IDE terminal is printing: "Enter two numbers:" and now is waiting on input due to the next line in your code: int num1 = in.nextInt();. just click on your terminal and see if you can enter an input and click enter on your keyboard, that should do the trick

CodePudding user response:

u are right ,bro.

u need to click on the console and enter param.

enter image description here

  • Related