readDouble方法对于该类型是未定义的

huangapple go评论102阅读模式
英文:

The method is readDouble is undefined for the type

问题

import java.util.Scanner;

public class Pizza {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("你想要的比萨直径是多少?");
    double pizzadiameter = readDouble("输入比萨直径:");
    System.out.println("比萨的直径将是 " + pizzadiameter + "。");
  }
}
英文:
import java.util.Scanner;
public class Pizza {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("what is the diameter of the pizza that you want?");
    double pizzadiameter = readDouble("Enter pizza diameter: ");
    System.out.println("The diameter of the pizza will be " + pizzadiameter + ".");
                         
  }
}

My problem is that double pizzadiameter = readDouble("Enter pizza diameter: "); (line 6) is giving me an error saying the method is undefined.

答案1

得分: 0

你需要使用 input.nextDouble 来获取输入:

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("你想要的比萨直径是多少?");
    double pizzadiameter = input.nextDouble();
    System.out.println("比萨的直径将会是 " + pizzadiameter + "。");
}
英文:

you need to get the input using input.nextDouble

    public static void main (String[] args) {
      
    	  Scanner input = new Scanner(System.in);
    	    System.out.println("what is the diameter of the pizza that you want?");
    	    double pizzadiameter = input.nextDouble(); 
    	    System.out.println("The diameter of the pizza will be " + pizzadiameter + ".");
    	    
    }

huangapple
  • 本文由 发表于 2020年10月8日 07:11:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64253553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定