0
Having difficulty with requesting for user input in the eclipse
Having difficulty with requesting for user input in the eclipse
5 Respostas
+ 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);
+ 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();
+ 8
if you want something to pop up, try
String name =JOptionPane.showInputDialog ("Enter your name");
System.out.println (name);
+ 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
+ 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