学校作业,所以这段代码没有意义。每当我尝试使用 char 时,我似乎总是会收到此错误
LetsGoShop.java:14: error: cannot find symbol
item = input.nextChar();
^
symbol: method nextChar()
location: variable input of type Scanner
1 error
继承人的实际代码:
import java.util.Scanner;
public class LetsGoShop {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
char item ;
int price;
int quantity;
System.out.println(" Enter the name of the item : ");
item = input.nextChar();
System.out.println(" Enter the price of said item : ");
price = input.nextInt();
System.out.println(" Enter how much of said item you want to buy : ");
quantity = input.nextInt();
double total = price * quantity ;
item = Character.toUpperCase(item);
System.out.println(" You owe " +total+ " for " +quantity + item);
}
}
我刚刚开始编码,所以如果答案很明显,我不会猜到的。