🌐
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); } }
🌐
w3resource
w3resource.com › java-exercises › basic › index.php
Java Basic Programming Exercises - w3resource
Write a Java program that accepts two integer values from the user and returns the largest value. However if the two values are the same, return 0 and find the smallest value if the two values have the same remainder when divided by 6.
🌐
W3Schools
w3schools.com › java › exercise.asp
Exercise: - JAVA User Input
I completed one of the JAVA exercises on w3schools.com
🌐
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
🌐
LabEx
labex.io › tutorials › java-java-scanner-input-challenge-413835
Java Scanner Tutorial: Learn User Input in Java Programming | LabEx
Improve your Java skills with our interactive Scanner input challenge. Learn to read user data, use variables, and create dynamic console outputs in this beginner-friendly Java programming exercise.
🌐
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
Find elsewhere
🌐
Intro to Java
redi-school.github.io › intro-java › lesson4 › scanner.html
Scanner - Intro to Java
The following exercises shall introduce you to Scanner which is used to get input from the user. Please do the following exercises. Feel free to discuss your solutions with your neighbours. Write the things you found out down to share them later with the class. import java.util.Scanner; public class ScannerExperiments { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("What is your name?"); String name = input.nextLine(); System.out.println("It's me, " + name + "!"); } }
🌐
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.
🌐
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:
🌐
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(); } }
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-exercises
Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
October 9, 2025 - Input: str1 = "Silent" str2 ="Listen" Output: Strings are Anagram Explaination: As all the elements in str1 are exact same as to create str2 .
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-Scanner-User-Input-example-String-next-int-long-char
Java Scanner User Input Example
This tutorial on how to use the Java Scanner for user input will quickly show you how to import java.util, take String, int, double and char input, and teach you the difference between the ...
🌐
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).
🌐
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: ...
🌐
Reddit
reddit.com › r/learnjava › user input program
r/learnjava on Reddit: User input program
September 6, 2021 -

Hi - Im learning Java and doing a course in my UNI where I am asked to create a program.

The exercise is to create a program that handles user input and converts it to the correct format. The user indicates the type of input that he/she will be providing and then follows that up by stating the actual input.

The types of input are: int / double / string

The program first asks the user to indicate the type of input

This is my code so far:

import java.util.Scanner;
public class UserInput {

public static void main(String[] args) {
// Write your code here
Scanner scanner = new Scanner(System.in);
// Scanner for user input
System.out.println("Please input the type of input you would like to print:");
String message = scanner.nextLine();
int intValue = Integer.parseInt(scanner.nextLine());
double doubleNumber = Double.parseDouble(scanner.nextLine());
System.out.println("Please give the input:");
}
}

This is wrong and I know that, but I'm struggling to figure out how to create a program that scans the user input and decides if it's a string/int or double. I tried using a converter as I figured that the user input would be a string as it's indicating by writing "int" or "double" or "string" hoping that my program would pick up on the next line and decide if it was an int/string or double. But as I realized myself, using .nextLine() on all three of them makes this complicated.

Any suggestions?

🌐
CodeGym
codegym.cc › java-coding-practice
Java Coding Practice | Improve Your Skills with Free Java Exercises
Explore the Java coding exercises for practicing with commands below. First, read the conditions, scroll down to the Solution box, and type your solution.