Advertisement
MrDoyle

7) User Input

Jan 14th, 2021
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main (String[] args){
  5.  
  6.         //Create scanner object
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         // Output the prompt
  10.         System.out.println("Enter a line of text: ");
  11.  
  12.         // Wait for the user to enter a line of text
  13.         String line = input.nextLine();
  14.  
  15.         // Tell them what they entered
  16.         System.out.println("You entered: " + line);
  17.  
  18.  
  19.  
  20.  
  21.         //Create scanner object
  22.         Scanner input2 = new Scanner(System.in);
  23.  
  24.         // Output the prompt
  25.         System.out.println("Enter an integer: ");
  26.  
  27.         // Wait for the user to enter something
  28.         int value = input.nextInt();
  29.  
  30.         // Tell them what they entered
  31.         System.out.println("You entered: " + value);
  32.  
  33.  
  34.  
  35.         //Create scanner object
  36.         Scanner input3 = new Scanner(System.in);
  37.  
  38.         // Output the prompt
  39.         System.out.println("Enter an decimal number: ");
  40.  
  41.         // Wait for the user to enter something
  42.         double decimal = input.nextDouble();
  43.  
  44.         // Tell them what they entered
  45.         System.out.println("You entered: " + decimal);
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement