2016-02-15 179 views
-2

嘿,我不明白爲什麼這個代碼是錯誤的我很確定我做了一切正確的邏輯明智。我認爲它的大小寫敏感我是對的嗎?錯誤:找不到符號?

import java.util.Scanner; 
public class Letgoshop 
{ 
    public static void main(String[] args) 
{ 
Scanner input = new Scanner(System.in); 

System.out.println("Enter item: "); 
String name = input.nextline(); 

System.out.println("Enter Price: "); 
double price = input.nextdouble(); 

System.out.println("Enter Quantity: "); 
int m = input.nextint(); 

System.out.print("You owe $" + m*price + " for " + m + " " + name.toUpperCase() +"(S)"); 

} 
} 
+0

Java是大小寫敏感的。 'nextline(); - > nextLine();','nextdouble(); - > nextDouble()'等。 –

回答

0

你拼寫錯誤的Scanner方法名,他們應該是:

System.out.println("Enter item: "); 
String name = input.nextLine(); 

System.out.println("Enter Price: "); 
double price = input.nextDouble(); 

System.out.println("Enter Quantity: "); 
int m = input.nextInt(); 
0

嘗試更正Scanner類的這些方法名稱:

input.nextline(); 
... 
input.nextdouble(); 
... 
input.nextint(); 

與正確的書寫他們名稱因爲java區分大小寫:

input.nextLine(); 
... 
input.nextDouble(); 
... 
input.nextInt(); 
0

Java區分大小寫,您拼寫錯誤的方法。
nextline() - > nextLine()
nextdouble() - > nextDouble()

import java.util.Scanner; 

public class Letgoshop { 

    public static void main(String[] args) { 
     Scanner input = new Scanner(System.in); 

     System.out.println("Enter item: "); 
     String name = input.nextLine(); 

     System.out.println("Enter Price: "); 
     double price = input.nextDouble(); 

     System.out.println("Enter Quantity: "); 
     int m = input.nextInt(); 

     System.out.print("You owe $" + m * price + " for " + m + " " + name.toUpperCase() + "(S)"); 

    } 
}