I want to take an input from the user to make a calculation based on user input in java please someone explain to me this?
thanks
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers 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.
Please briefly explain why you feel this user should be reported.
In Java the Scanner class allows the user to take input from the console. It belongs to the java.util package.It is used to read the input of primitive types like int, double, long, short, float, and byte.
You can use this example below to understand the way the Scanner class helps to take input from the user
import java.util.*;
class UserInputDemo1
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in); //System.in is a standard input stream
System.out.print(“Enter your name: “);
String str= sc.nextLine(); //reads string
System.out.print(“Your name is : “+str);
}
}
Output :
Your name is : Sourav //In this case I have taken Input as Sourav so it is printing in the console as Your name is : Sourav