Having difficulty with requesting for user input in the eclipse | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Having difficulty with requesting for user input in the eclipse

Having difficulty with requesting for user input in the eclipse

14th Apr 2017, 11:43 AM
Afful Graham
Afful Graham - avatar
5 Answers
+ 23
According to your code, you'll have to enter the input in console first, then it'll show the output. If you want to show the user a prompt message first, then print a prompt message as follows: Scanner nameScan = new Scanner(System. in); System.out.println("Enter your name: "); // prompt message String name = nameScan.nextLine(); System.out.println(name);
14th Apr 2017, 12:52 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 22
Can you share your code here? Here is a sample code to take integer input : Scanner sc = new Scanner (System.in); System.out.println("Enter an integer : "); int num = sc.nextInt(); sc.close();
14th Apr 2017, 12:04 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 8
if you want something to pop up, try String name =JOptionPane.showInputDialog ("Enter your name"); System.out.println (name);
14th Apr 2017, 1:35 PM
Edward
+ 5
nothing pops up in eclipse. click on the console and type your input right there.. Popup input is a workaround for things like codeplayground that aren't actual consoles
14th Apr 2017, 12:43 PM
LordHill
LordHill - avatar
+ 1
import java.util.Scanner; class MyClass { public static void main(String[] arts) { Scanner nameScan = new Scanner(System. in); String name = nameScan.nextLine(); System. out.println(name); } } after clicking run in the eclipse nothing pop up for input
14th Apr 2017, 12:32 PM
Afful Graham
Afful Graham - avatar