Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Why do I need to parse a double into a double?

Hey, I did this code with a video tutorial:

Code
import java.util.*;

public class DatenEingabe
{
    public static void main(String[] args)
    {
        Scanner leser = new Scanner(System.in);
        int anzahl;
        double preis;
        String bezeichnung, eingabe;
        
        System.out.print("Geben Sie einen Preis ein: ");
        eingabe = leser.nextLine();
        preis = Double.parseDouble(eingabe);
        System.out.printf("Anzahl: %.2f € %n", preis);
        
        leser.close();
    }
    
    
}

Why do I need to parse my preis variable to a double, if I declared the variable as a double above? Why don't I need to to this with Strings? .. [/php]
Feel free to ask me any question about RAT's. I am there to answer them all. My skype is: kim.kertani
Did you code this, fellow German, or did you literally copy 1:1 german code? 🤣
(Apr 8, 2017 10:25 AM)Katarina Du Couteau Wrote:  Did you code this, fellow German, or did you literally copy 1:1 german code? 🤣

I coded this as a German, from a German video by Rheinwerk Verlag ^^
https://www.rheinwerk-verlag.de/programm...java_3867/
Feel free to ask me any question about RAT's. I am there to answer them all. My skype is: kim.kertani
You don't need to parse it as a double; you can simply call Scanner#nextDouble instead.
Edit: Ninja'd rippppoooppp


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by XoggApr 24, 2020 01:14 AM 2 138 Apr 24, 2020 01:14 AM
Last Post: Lindros
[Shell] by ProfitableFlipMay 24, 2019 09:40 AM 1 163 May 24, 2019 09:40 AM
Last Post: Adolf
[C#] by -PUBG-Nov 11, 2018 01:14 PM 18 780 Nov 11, 2018 01:14 PM
Last Post: Slart