Hack Forums
[Java] Why do I need to parse a double into a double? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Why do I need to parse a double into a double? (/showthread.php?tid=5595205)



Why do I need to parse a double into a double? - ♥Quantum♥ - Apr 8, 2017

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]


* - Katarina Du Couteau - Apr 8, 2017

Did you code this, fellow German, or did you literally copy 1:1 german code? 🤣


* - ♥Quantum♥ - Apr 8, 2017

(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/programmieren-lernen-mit-java_3867/


* - Stealth™ - Apr 8, 2017

You don't need to parse it as a double; you can simply call Scanner#nextDouble instead.


* - thepixelhacker - Apr 8, 2017

Edit: Ninja'd rippppoooppp