所以我必须编写一个执行以下操作的程序:
我不确定为什么我的程序不起作用。它一直在说"无法解决符号"在letter.isUpperCase
和letter.isLowerCase
上。如果你们/ gals可以解决这个问题,如果你发现任何问题,请告诉我!提前谢谢!
import java.io.*;
class Letter {
public static void main(String[] args) throws IOException {
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader mVHS = new BufferedReader (inStream);
String inData; //Store the input data in a String
int length;//Assign the length to the int data type
String letter, result, result2; //Store the sentence in the String type
//Enter a letter
System.out.println("Type a letter one at a time");
System.out.println("Press enter when a letter is entered");
System.out.println("When done typing all the letters, press . to end the program");
System.out.println("Enter a letter:");
String userInput = mVHS.readLine();
letter = userInput;
result = letter.toUpperCase();
result2 = letter.toLowerCase();
if (letter.isUpperCase(letter.charAt(0)))
System.out.println(result);
else if (letter.isLowerCase(letter.charAt(0)))
System.out.println(result2);
//while loop if sentence does not end with a "."
while(letter.length() == 1){
{
if (letter.endsWith("."))
System.out.println("Thank you come again."); //What the monitor outputs in this condition
else
System.out.println("Enter another letter:");//What the monitor outputs in this condition
userInput = mVHS.readLine();
letter = userInput;
}
}
}
}
答案 0 :(得分:0)
isUpperCase
上没有名为isLowerCase
或String
的方法。所以,从
letter.isUpperCase(letter.charAt(0))
到
Character.isUpperCase(letter.charAt(0));
答案 1 :(得分:0)
检查以下代码
import java.io.*;
班级信{ public static void main(String [] args)抛出IOException {
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader mVHS = new BufferedReader (inStream);
String letter; //Store the sentence in the String type
//Enter a letter
System.out.println("Type a letter one at a time");
System.out.println("Press enter when a letter is entered");
System.out.println("When done typing all the letters, press . to end the program");
System.out.println("Enter a letter:");
String userInput = mVHS.readLine();
letter = toggleCase(userInput);
System.out.println(letter);
//while loop if sentence does not end with a "."
while(letter.length() == 1){
{
if (letter.endsWith("."))
System.out.println("Thank you come again."); //What the monitor outputs in this condition
else
System.out.println("Enter another letter:");//What the monitor outputs in this condition
userInput = mVHS.readLine();
letter = toggleCase(userInput);
System.out.println(letter);
}
}
}
private static String toggleCase(String userInput) {
String letter;
String upperString;
letter = userInput;
upperString = letter.toUpperCase();
if (letter.equals(upperString)){
return (letter.toLowerCase());
}
else{
return (upperString);
}
}
}