Advertisement
CR7CR7

PrintOnTheConsole

Sep 12th, 2022
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package com.telerikacademy;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ScannerDemo {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         System.out.print("Enter a number: ");
  10.         int number = scanner.nextInt();
  11.  
  12.         System.out.print("Enter a floating-point number: ");
  13.         double doubleNumber = scanner.nextDouble();
  14.  
  15.         System.out.print("Enter a string: ");
  16.         String str = scanner.next();
  17.  
  18.         // Print on the console variables you entered
  19.         // Use %d for decimal numbers
  20.         // Use %.f for floating-point numbers
  21.         // Use %s for the text
  22.         // Use %n for new line
  23.         System.out.printf(
  24.                 "Number: %d%nFloating-point number: %f%nString: %s",
  25.                 number,
  26.                 doubleNumber,
  27.                 str);
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement