User Tools

Site Tools


java:util:scanner

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

java:util:scanner [2013/04/08 09:02]
94.222.245.67
java:util:scanner [2024/02/16 01:03] (current)
Line 2: Line 2:
 Reads input from a Keyboard, or a Device Reads input from a Keyboard, or a Device
  
-===== example Scanner =====+CODE_SIGN_IDENTITY 
 + 
 +--verify 
 + 
 +--file-list 
 + 
 +--display -r- Terminal.app 
 + 
 + 
 + 
 +===== example Scanner in java =====
 <code java> <code java>
 package scanner; package scanner;
 +
 +import java.util.Scanner;
  
 public class Scanner { public class Scanner {
Line 10: Line 22:
     public static void main(String[] args) {     public static void main(String[] args) {
                  
-        /* Scanner for the input from the keyboard */ +        /* Create Scanner Object for the input from the keyboard */ 
-        java.util.Scanner scan = new java.util.Scanner(System.in); +        Scanner scan = new Scanner(System.in); 
                  
         double currency, amount, exchangeRate;         double currency, amount, exchangeRate;
Line 17: Line 29:
                                  
         System.out.print("Please enter the amount (with decimal places) a of Change done to: ");         System.out.print("Please enter the amount (with decimal places) a of Change done to: ");
-        currency = scan.nextFloat(); // read currency+        currency = scan.nextDouble(); // read currency
         System.out.print("Enter the name of the currency: ");         System.out.print("Enter the name of the currency: ");
-        currencyName = scan.next();/* read String*/+        currencyName = scan.nextLine();/* read String*/ 
 +         
 +        scan.nextLine(); // clear the keyboard buffer ... trow a \n away
                  
         System.out.print("Please enter the exchange rate (with decimal places): ");         System.out.print("Please enter the exchange rate (with decimal places): ");
-        exchangeRate = scan.nextFloat();+        exchangeRate = scan.nextDouble();
         System.out.print("Please enter the new currency name: ");         System.out.print("Please enter the new currency name: ");
-        newCurrency = scan.next();+        newCurrency = scan.nextLine();
                  
         /* calculate the new amount */         /* calculate the new amount */

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
java/util/scanner.1365404573.txt · Last modified: 2024/02/16 01:02 (external edit)

Impressum Datenschutz