Java - 扫描程序/符号错误

时间:2018-04-06 03:42:06

标签: java symbols

我对此非常陌生,正在学习初学者的Java课程。任务是搜索字符串以获取信息,但收到以下错误。

首先,代码。

/***********************************************************************
* Identify if webpage is secure or unencrypted given full HTML path    *
***********************************************************************/

import java.io.*;
import java.lang.*;
import java.util.Scanner;

public class stringy {

    public static void main (String args[]) {

    Scanner userInput = new Scanner(System.in);
    System.out.print("Paste the web address into the prompt: ");   //collect web address from user
    String webPath = scan.next();

    CharSequence seq = "https://";                     //search for https:
    boolean testCase = test.contains(seq);
    System.out.println("Found https://" + testCase);

    boolean testPositive = test.contains("https://");     //if found https, notify user
    System.out.println("This website is secure.  Continue exercising caution while browsing.");

    CharSequence seq2 = "http://";                     //search for https:
    boolean testCase2 = test.contains(seq2);
    System.out.println("Found https://" + testCase2);

    boolean testNegative = test.contains("http://");     //if found http, notify user
    System.out.println("This website is unencrypted!" + '\n');
    System.out.println("Do not post personal or sensitive information in any form or field on this page." + '\n');
    }
}

错误输出:

C:\Users\name\Documents\School\Intro to Programming (JAVA)\Week 3\stringy.java:15: error: cannot find symbol  
    String webPath = scan.next();  
                     ^  
  symbol:   variable scan  
  location: class stringy  
C:\Users\name\Documents\School\Intro to Programming (JAVA)\Week 3\stringy.java:18: error: cannot find symbol  
    boolean testCase = test.contains(seq);  
                       ^  
  symbol:   variable test  
  location: class stringy  
C:\Users\name\Documents\School\Intro to Programming (JAVA)\Week 3\stringy.java:21: error: cannot find symbol  
    boolean testPositive = test.contains("https://");     //if found https, notify user  
                           ^  
  symbol:   variable test  
  location: class stringy  
C:\Users\name\Documents\School\Intro to Programming (JAVA)\Week 3\stringy.java:25: error: cannot find symbol  
    boolean testCase2 = test.contains(seq2);  
                        ^  
  symbol:   variable test  
  location: class stringy  
C:\Users\name\Documents\School\Intro to Programming (JAVA)\Week 3\stringy.java:28: error: cannot find symbol  
    boolean testNegative = test.contains("http://");     //if found http, notify user  
                           ^  
  symbol:   variable test  
  location: class stringy  
5 errors  

Tool completed with exit code 1

1 个答案:

答案 0 :(得分:0)

您的代码中有两个问题:

<强>第一

  

您已指定扫描仪使用此行:   Scanner userInput = new Scanner(System.in);

     

因此,您应该使用userInput代替此行进行扫描:String webPath = scan.next(); String userInput = scan.next();

第二

  

在使用之前没有设置测试变量,所以在使用之前分配测试变量。