简体   繁体   中英

Java Code User Input to System.out

Small programming question here.

I'm trying to get line 43

System.out.print("Please Enter the Manufacturer of Your Doughnut:"); 

user input to paste directly into line 46

System.out.print("Please Enter the Manufacturer of Your Doughnut:"); 

but my compiler keeps giving me this error:

Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at Torus.main(Torus.java:46)

For example, if the user wanted to input that their doughnuts were from McDonald's, line 46 would automatically spit out McDonald's.

我的Java代码

Well with input.nextDouble() the compiler is expecting a Double-Datatype. You need to get a string as manufacturer. I Think input.nextLine() should do it.

manufacturer类型从double更改为String ,然后使用:

manufacturer = input.nextLine();

If you need the manufacturer variable to store a name, it should be of type String not double .
Change your declaration to

String manufacturer;

and to accept input use

manufacturer=input.nextLine(); //returns String

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM