我一直收到一个错误,说无法找到符号 - 可变键盘

时间:2014-09-14 11:20:04

标签: java

  import javax.swing.JOptionPane;
  import java.io.File;
  import java.util.Scanner;
  public class Map{
  public static void main(String[] args){ 

  // create a Scanner object 
  Scanner input = new Scanner(System.in);

 //Prompt the user to enter three numbers in inches 
 System.out.print("enter four numbers:");
 double distance1 = input.nextDouble();
 double distance2 = input.nextDouble();
 double distance3 = input.nextDouble();
double distance4 = input.nextDouble();

 //public classify DistanceScale

    //Make a constant to hold kilometers to miles conversion
    //final const MILESTOKILOS = 1.609344;

    // Explain the program to the user
    System.out.println("Welcome! This program calculates true distance from map measurements You can enter up to 4 distances");
    System.out.println();

    // ask user for 4 distances, from the map.
    System.out.print("Enter distance 1 (in inches): ");
    double distancel = keyboard.nextdouble();

    System.out.print("Enter distance 2 (in inches): "); 
    double distance2 = keyboard.nextdouble();        

    System.out.print = "Enter distance 2 (in inches): ";
    double distance3 = keyboard.nextdouble();

    // determine total miles from total inches
    // Scale:  1 inch is 1/4 mile
    double totalMiles = totalInches * 1/4;        
    // add to get total inches on map
    distance1 + distance2 + distance2 + distance4 = totalInches;

    //round to one-tenth of a mile 
    int miles =(totalMiles + 0.05) * 10;

    //total miles
    int totalMiles = 10%

    // calculate kilometers
    totalKilos = totalMiles * miles * kilos;

    // round kilometers to tenths
    //int class kilos = totalKilos + {005 * 10)};
    //totalKilos = kilos / 100;

    // print results
    System.out.printn("Total inches:     " + "totalInches");
    Sytem.out.println ("Total miles:      " + milesTotal);
    System.out.prntln("Total kilometers: totalKilos");
    {
    }

我的所有double distancel = keyboard.nextdouble();我不熟悉java,并且我正在使用名为bluej的程序。我不明白为什么它说键盘需要变量。如果你们可以帮我解决这个错误,那就太好了。我总是喜欢学习。谢谢!

2 个答案:

答案 0 :(得分:1)

您正在尝试引用未声明的变量,这就是编译器说他找不到keyboard的原因。

只需将所有keyboard个引用替换为input

似乎是拼写错误或复制和粘贴错误。

答案 1 :(得分:0)

您的Scanner被称为input,而不是keyboard您应该在此处调用时更改它,例如:
double distancel = keyboard.nextdouble();将其更改为double distancel = input.nextdouble();

我还看到了另一件事:

totalKilos = totalMiles * miles * kilos;

您没有任何声明的变量totalKilos来为其赋值。

你应该int totalKilos = totalMiles * miles * kilos;

同样的事情:distance1 + distance2 + distance2 + distance4 = totalInches;

我认为你想做double totalInches = distance1 + distance2 + distance2 + distance4;

相关问题