How to create a program that can give user input in Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
class example{
import java.util.Scanner;
public static void main(String args[]){
System.out.println(“Enter Your Name”);
Scanner s1 = new Scanner(System.in);
String name = s1.nextLine();
System.out.println(“Your name is “+name);
}
}
සමාවෙන්න. Typing mistake එකක්.
import java.util.Scaner class එකට උඩින් එන්න ඕනේ
ok
import java.util.Scanner;
public class mypro {
public static void main(String args[ ] ) {
Scanner reader = new Scanner (System.in);
String na = reader.nextInt ( );
}
}
1. The first line here imports the Scanner class in Java. 2,3 Codes are common in Line Java programs.
2. Line 4 reads the data in System.in related to the Scanner Class. Accordingly, that data is used to get input from the keyboard. Here they are obtained for the object called reader.
3. In line 5, na indicates the String type Variable One. When this is activated, Use notes something As soon as you press the Enter button on the keyboard, the input is stored in the variable na.
මේකේ
String na = reader.nextLine(); වෙන්න ඕනේ. nextInt() දෙන්න බැහැ.String value එකක් නිසා nextLine() දෙන්න ඕනේ ⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
Sorry a mistake
import java.util.*;
class Demo{
public static void main(String[] args){
Scanner input=new Scanner(System.in);//–> import scanner
String name;//–>declare a string variable
System.out.println(“Enter user input”);
name=input.nextLine();//–>read string value
System.out.println(name);//–>print string value
}
}