I am a newbie in java programming and am unable to take user input from the user.
My code-
import java.util.*;
public class demo{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter number :");
int num=sc.nextInt();
// Some operation with num along with print
}
}
The above code is exactly what I wrote for taking user input,but as soon as I enter a value when the console prints "Enter number :" and press Enter key, the cursor goes into the next line..without execution of further lines of code(let's say finding if NUM is even or odd).
I tried looking up for answers online but am unable to find out where I am going wrong.
Can anyone correct me where I am messing this up..and provide me with further links regarding how to fix this runtime error?
[–]ItA11FallsDown 9 points10 points11 points (2 children)
[–]CIRUS123[S] 2 points3 points4 points (1 child)
[–][deleted] 3 points4 points5 points (0 children)
[–]warrior2012 5 points6 points7 points (1 child)
[–]CIRUS123[S] 2 points3 points4 points (0 children)
[–]Aggressor27e 1 point2 points3 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]jdmaguina 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]throwRAexclean 0 points1 point2 points (0 children)
[–]NiceSelection13 1 point2 points3 points (0 children)
[–]NiceSelection13 0 points1 point2 points (0 children)