How to read input from Console using Scanner Class

0 votes
How to take input from user through console using Scanner Class in Java?
Apr 18, 2018 in Java by Daisy
• 8,140 points
5,182 views

3 answers to this question.

0 votes

To take input from user through Console, we have to import Scanner class from Util Library.

import java.util.Scanner;

Once we create an object of Scanner Class, we can easily take user input.

System.out.println("Enter your name: ");
Scanner s = new Scanner(System.in);
String name = s.nextLine();
System.out.println("Your username is " + name);
answered Apr 18, 2018 by Parth
• 4,640 points
0 votes
Scanner scan = new Scanner(System.in);
String myLine = scan.nextLine();
answered Jul 13, 2018 by Sushmita
• 6,920 points
0 votes

A simple example:

import java.util.Scanner;

public class Expl
{
    public static void main(String[] args)
    {
        int number1, number2, sum;

        Scanner input = new Scanner(System.in);

        System.out.println("Enter First multiple");
        number1 = input.nextInt();

        System.out.println("Enter second multiple");
        number2 = input.nextInt();

        sums = number1 * number2;

        System.out.printf("The product of both number is %d", sum);
    }
}
answered Aug 1, 2018 by samarth295
• 2,220 points

Related Questions In Java

0 votes
1 answer

Is there a way to mask the password from java user input that comes from Scanner class and System.out.Println()?

You can use the console class to do so. ...READ MORE

answered May 27, 2019 in Java by Omkar
• 69,220 points
11,099 views
0 votes
1 answer

How to take input from users?

Scanner Class is used to take input ...READ MORE

answered Apr 17, 2018 in Java by Akrati
• 3,190 points
794 views
0 votes
3 answers

Is it possible to take char input from scanner?

// Use a BufferedReader to read characters ...READ MORE

answered Sep 7, 2018 in Java by Daisy
• 8,140 points
9,081 views
0 votes
1 answer

How to read text files from the Classpath in Java?

InputStream in = this.getClass().getClassLoader().getResourceAsStream("TextFile.txt"); InputStream in = this.getClass().getResourceAsStream("/TextFile.txt"); package ...READ MORE

answered May 8, 2018 in Java by Akrati
• 3,190 points
2,829 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,223 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,359 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,433 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,875 views
0 votes
2 answers

How to get input from user using System.console()?

Scanner in = new Scanner(System.in); int i = ...READ MORE

answered Aug 2, 2018 in Java by Sushmita
• 6,920 points
1,097 views
0 votes
2 answers

How to read the files using Java?

You can use collections. try (Stream<Path> filePathStream=Files.walk(Paths.get("/home/you/Desktop"))) { ...READ MORE

answered Jul 10, 2018 in Java by Sushmita
• 6,920 points
1,117 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP