User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







java:util:scanner

This is an old revision of the document!


Scanner()

Reads input from a Keyboard

example Scanner

package scanner;
 
public class Scanner {
 
    public static void main(String[] args) {
 
        /* Scanner für die Eingabe von der Tastatur einbinden */
        java.util.Scanner scan = new java.util.Scanner(System.in);
 
        double currency, amount, exchangeRate;
        String currencyName, newCurrency;
 
        System.out.print("Please enter the amount (with decimal places) a of Change done to: ");
        currency = scan.nextFloat(); // betrag auslesen
        System.out.print("Enter the name of the currency: ");
        currencyName = scan.next();/* Zeichen auslesen*/
 
        System.out.print("Please enter the exchange rate (with decimal places): ");
        exchangeRate = scan.nextFloat();
        System.out.print("Please enter the new currency name: ");
        newCurrency = scan.next();
 
        /* Berechnung des neuen Betrags */
        amount = currency * exchangeRate;
 
        System.out.println(
                java.lang.Math.round(currency)+" \""
                +currencyName+" \" are "
                +java.lang.Math.round(amount)+" \""
                +newCurrency+"\"");
 
        scan.close(); // close the object 
    }
}

output of scanner

  Please enter the amount (with decimal places) a of Change done to: 42,0
  Enter the name of the currency: Euro
  Please enter the exchange rate (with decimal places): 1,2993
  Please enter the new currency name: Doller
  42 "Euro " are 55 "Doller"

on the occasion of the current invasion of Russia in Ukraine

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

Impressum Datenschutz