【发布时间】:2018-04-06 03:42:05
【问题描述】:
我对此很陌生,正在学习 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
【问题讨论】:
-
使用
userInput而不是scan。例如:String webPath = userInput.next(); -
您的扫描仪被命名为
userInput而不是scan.... 测试变量设置在哪里? -
请记住,大多数开发人员使用 IDE,它通常会在您尝试运行代码之前突出显示这些错误
-
@cricket_007 - 我会检查的。这可能是问题所在!