W3Schools
w3schools.com › java › java_user_input.asp
Java User Input (Scanner class)
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); System.out.println("Enter name, age and salary:"); // String input String name = myObj.nextLine(); // Numerical input int age = myObj.nextInt(); double salary = myObj.nextDouble(); // Output input by user System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Salary: " + salary); } }
Videos
GeeksforGeeks
geeksforgeeks.org › java › java-user-input-scanner-class
Java User Input - Scanner Class - GeeksforGeeks
Exercises · Examples · Quizzes ... · Try it on GfG Practice · The most common way to take user input in Java is using the Scanner class....
Published July 23, 2025
Tutorialspoint
tutorialspoint.com › java › java_user_input.htm
Java - User Input
The above statement will wait for an integer input from the user. When user provides an integer value, that will be assign to "age" variable. In the following example, we are reading two integers from the user, calculating, and printing their addition − · // Importing the class import java.util.Scanner; public class AddTwoNumbers { public static void main(String[] args) { // Creating an object of Scanner class Scanner sc = new Scanner(System.in); // Reading two Integer numbers // using nextInt() method System.out.print("Enter the first number: "); int num1 = sc.nextInt(); System.out.print("Enter the second number: "); int num2 = sc.nextInt(); // Calculating the sum int sum = num1 + num2; // Printing the su System.out.println("The sum of the two numbers is: " + sum); } }
w3resource
w3resource.com › java-exercises › io › index.php
Java Input Output Exercises - w3resource
This resource offers a total of 90 Java Input-Output problems for practice. It includes 18 main exercises, each accompanied by solutions, detailed explanations, and four related problems.
W3Schools
w3schools.com › java › java_exercises.asp
Java Exercises
close() delimiter() findInLine() findWithinHorizon() hasNext() hasNextBoolean() hasNextByte() hasNextDouble() hasNextFloat() hasNextInt() hasNextLine() hasNextLong() hasNextShort() locale() next() nextBoolean() nextByte() nextDouble() nextFloat() nextInt() nextLine() nextLong() nextShort() radix() reset() useDelimiter() useLocale() useRadix() Java File Methods Java FileInputStream Java FileOutputStream Java BufferedReader Java BufferedWriter Java Iterator Methods Java Collections Methods Java System Methods Java Errors & Exceptions · Java Examples Java Compiler Java Exercises Java Quiz Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate
Programiz
programiz.com › java-programming › basic-input-output
Java Basic Input and Output
In this tutorial, you will learn simple ways to display output to users and take input from users in Java. We will use the print() method to display output and the Scanner class to take input.
CodeWithHarry
codewithharry.com › tutorial › java-user-input-output
Input/Output | Java Tutorial | CodeWithHarry
Let us see different methods to take inputs. Below are the methods that belong to the scanner class: ... import java.util.Scanner; public class ScannerExample { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter Name, RollNo, Marks, Grade"); String name = sc.nextLine(); //used to read line int RollNo = sc.nextInt(); //used to read int double Marks = sc.nextDouble(); //used to read double char Grade = sc.next().charAt(0); //used to read till space System.out.println("Name: "+name); System.out.println("Gender: "+RollNo); System.out.println("Marks: "+Marks); System.out.println("Grade: "+Grade); sc.close(); } }
TheServerSide
theserverside.com › tutorial › Your-top-Java-user-input-strategies
Your top 4 Java user input strategies | TheServerSide
Render a JOptionPane to easily generate message boxes and input dialog boxes in Java. In earlier versions of Java, developers could only obtain user input by chaining Java I/O classes, as follows:
CodeChef
codechef.com › blogs › java-user-input
How to accept User Input in Java (Examples and Practice)
Learn how to take user inputs in Java with this beginner-friendly guide. Discover string and integer inputs, handling multiple inputs, and practical examples to enhance your Java programming skills
w3resource
w3resource.com › java-exercises › conditional-statement › java-conditional-statement-exercise-12.php
Java - Input 5 numbers and find their sum and average
Write a program in Java to input 5 numbers from the keyboard and find their sum and average. ... import java.util.Scanner; public class Exercise12 { public static void main(String[] args) { int i,n=0,s=0; double avg; { System.out.println("Input ...
HWS Math
math.hws.edu › javanotes › c2 › ex3-ans.html
Javanotes 9, Solution to Exercise 3, Chapter 2
System.out.print("Please enter your name: "); usersName = TextIO.getln(); upperCaseName = usersName.toUpperCase(); System.out.println("Hello, " + upperCaseName + ", nice to meet you!"); } // end main() } // end class ... import java.util.Scanner; public class GreetingWithScanner { public static ...
Home and Learn
homeandlearn.co.uk › java › user_input.html
java for complete beginners - user input
How to get input from a user using the command line in java.
w3resource
w3resource.com › java-exercises › basic › java-basic-exercise-5.php
Java - Display the product of two numbers
import java.util.Scanner; public ... { // Create a Scanner object to read input from the user Scanner in = new Scanner(System.in); // Prompt the user to input the first number System.out.print("Input first number: "); // Read and store the first number int num1 = in.nextInt(); // Prompt the user to input the second number System.out.print("Input second number: "); // Read and store the second number // Calculate the product of the two numbers and display the result System.out.println(num1 + " x " + num2 + " = " + num1 * num2); } } Explanation: ...
GeeksforGeeks
geeksforgeeks.org › java › ways-to-read-input-from-console-in-java
Ways to Read Input from Console in Java - GeeksforGeeks
July 23, 2025 - Exercises · Examples · Quizzes · Projects · Cheatsheet · DSA in Java · Java Collection · Sign In ▲ · Open In App · Last Updated : 23 Jul, 2025 · Comments · Improve · Suggest changes · 269 Likes · Like · Report · Try it on GfG Practice · In Java, there are four different ways to read input from the user in the command line environment(console).