割り当ての場合、文字列を入力して反転する必要がありますが、文字列内の文字が文字、数字、または空白でない場合は、不正な文字例外がスローされます。私の教授は、メソッドの throw 句は必要ないと言っています。
これが私のコードです
import java.util.*;
import java.io.*;
public class reverse3
{
public static void reverse(String x)
{
char j;
String reversedString;
for(int i = 0; i < x.length(); i++)
{
try
{
if(!Character.isDigit(x.charAt(i)) && !Character.isLetter(x.charAt(i)) && !Character.isWhitespace(x.charAt(i)))
{
throw ( new IllegalCharacterException("Illegal Character in String"));
}//end if
else if(Character.isDigit(x.charAt(i)) && Character.isLetter(x.charAt(i)) && Character.isWhitespace(x.charAt(i)))
{
j = x.charAt(i);
j = reversedString.charAt(i - 1);
}//end else if
}//end try
catch(IllegalCharacterException e)
{
System.out.println(e.getMessage());
}//end catch
}//end for loop
}//end method
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String s;
System.out.println("Please enter a string");
s = keyboard.next();
reverse(s);
}//end main
}//end class
15 行目と 23 行目でこのエラーが発生し続けます エラー: IllegalCharacterException を型に解決できません