Hey there!
Welcome to ClearUrDoubt.com.
In this post, we will look at a Java program to accept inputs from the console and print them back to the output.
This can be achieved using the Scanner class defined in java.util package.
Here is the Java program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package com.sample.clearurdoubt; import java.util.Scanner; public class PracticeSystemInputs { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your name: "); String name = input.nextLine(); System.out.println("Enter your age: "); Double age = input.nextDouble(); System.out.println("Thank you for your inputs."); System.out.println(); System.out.println("Your name is " + name.trim() + " and your age is " + age + " years."); input.close(); } } |
Output:
Happy learning :).
Please leave a reply in case of any queries.