【问题标题】:Cannot find symbol on my scanners在我的扫描仪上找不到符号
【发布时间】:2014-12-28 05:11:25
【问题描述】:

尝试创建一个程序,允许您输入相框和图片的长度/宽度,然后比较两者以查看一个是否适合另一个。简单的东西,因为我是 Java 新手,但我离题了 - 这是代码:

import java.util.Scanner;

public class pictureFrame {
   public static void main(String[] args) {
      double x = 0;
      double y = 0;
      double u = 0;
      double v = 0;

      xScanner = new Scanner(System.in);
      yScanner = new Scanner(System.in);
      uScanner = new Scanner(System.in);
      vScanner = new Scanner(System.in);

      System.out.println("Enter the length of the picture");
      x = xScanner.nextDouble();
      System.out.println("Enter the width of the picture");
      y = yScanner.nextDouble();
      System.out.println("Enter the length of the frame");
      u = uScanner.nextDouble();
      System.out.println("Enter the width of the frame");
      v = vScanner.nextDouble();

      if (x = u && y = v)
      {
        System.out.println("The frame fits the picture!");
      }
        else if (x == v && y == u) 
        {
            System.out.println("The frame fits the picture!");
        } 
               else 
              {
                  System.out.println("The frame does not fit the picture");
              }

         }

     }
     }

我收到了 8 个错误,都说他们找不到以下每一行的第一个字符的符号:

  xScanner = new Scanner(System.in);
  yScanner = new Scanner(System.in);
  uScanner = new Scanner(System.in);
  vScanner = new Scanner(System.in);
  x = xScanner.nextDouble();
  y = yScanner.nextDouble();
  u = uScanner.nextDouble();
  v = vScanner.nextDouble();

对不起,如果这个问题很愚蠢,我确实事先使用了搜索功能。

【问题讨论】:

    标签: java find symbols


    【解决方案1】:

    你忘了把 Scanner 放在语句前面,也..你只需要声明一次 Scanner:

    Scanner scan = new Scanner(System.in);
    x = scan.nextDouble();
    y = scan.nextDouble();
    //etc..
    

    【讨论】:

      猜你喜欢
      • 2015-11-27
      • 2023-03-20
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-03
      • 1970-01-01
      相关资源
      最近更新 更多