[英]Java - Scanner/symbol errors
我對此很陌生,正在研究初學者的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
您的代碼中有兩個問題:
首先 :
您已將掃描儀分配給使用此行:
Scanner userInput = new Scanner(System.in);
因此,您應該在此行中使用
userInput
而不是scan:String webPath = scan.next();
如String userInput = scan.next();
第二
您尚未在使用前設置測試變量,因此請在使用前分配測試變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.