Java - Scanner/symbol 个错误
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
你的代码有两个问题:
第一个:
You have assigned scanner to using this line :
Scanner userInput = new Scanner(System.in);
So,you should use userInput
instead of scan in this line:String webPath = scan.next();
like String userInput = scan.next();
第二
You have not set test variable before using it so,assign the test variable before using.
我对此很陌生,正在学习初学者的 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
你的代码有两个问题:
第一个:
You have assigned scanner to using this line :
Scanner userInput = new Scanner(System.in);
So,you should use
userInput
instead of scan in this line:String webPath = scan.next();
likeString userInput = scan.next();
第二
You have not set test variable before using it so,assign the test variable before using.