//以下这段代码没有编译通过,编译时提示 使用SavitchIn.readLineNonwhiteChar这个类的地方 “找不到符合”,这里是不是需要包含一个什么包?具体怎么操作呢,感谢!
public class FirstProgram
{
public static void main(String[] args)
{
System.out.println("Hello out there.");
System.out.println("Want to talk some more?");
System.out.println("Answer y for yes or n for no.");
char answerLetter;
answerLetter = SavitchIn.readLineNonwhiteChar();
if (answerLetter == 'y')
System.out.println("Nice weather we are having.");
System.out.println("Good-bye.");
System.out.println("Press enter key to end...");
String junk;
junk = SavitchIn.readLine();
}
public class FirstProgram
{
public static void main(String[] args)
{
System.out.println("Hello out there.");
System.out.println("Want to talk some more?");
System.out.println("Answer y for yes or n for no.");
char answerLetter;
answerLetter = SavitchIn.readLineNonwhiteChar();
if (answerLetter == 'y')
System.out.println("Nice weather we are having.");
System.out.println("Good-bye.");
System.out.println("Press enter key to end...");
String junk;
junk = SavitchIn.readLine();
}
把它放到你的那个文件目录下.再编译就行了.import java.io.*;
import java.util.*;
public class SavitchIn
{
public static String readLine()
{
char nextChar;
String result = "";
boolean done = false;
while (!done)
{
nextChar = readChar();
if (nextChar == '\n')
done = true;
else if (nextChar == '\r')
{
//Do nothing.
//Next loop iteration will detect '\n'
}
else
result = result + nextChar;
}
return result;
}
public static char readLineNonwhiteChar()
{
boolean done = false;
String inputString = null;
char nonWhite = ' ';//To keep the compiler happy.
while (! done)
{
inputString = readLine();
inputString = inputString.trim();
if (inputString.length() == 0)
{
System.out.println(
"Your input is not correct.");
System.out.println("Your input must contain at");
System.out.println(
"least one nonwhitespace character.");
System.out.println("Please, try again.");
System.out.println("Enter input:");
}
else
{
nonWhite = (inputString.charAt(0));
done = true;
}
}
return nonWhite;
}}