Java:
package strings;
import java.io.FileNotFoundException;
import main.*;
import javax.swing.*;
public class StringToMorseCodeEncoder
{
static JFrame f;
public StringToMorseCodeEncoder() throws FileNotFoundException
{
String morseCode = "";
String[][] morseCodeAlphabet = {{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."}, {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."}};
String s = Utils.enterFileOrString(f, "Enter the string you want to encode to Morse Code");
for(int i = 0; i <= s.length(); i++)
{
char c = s.charAt(i);
if(c >= 'A' && c <= 'Z')
{
morseCode += morseCodeAlphabet[0][c - 'A'] + "";
}
if(c >= '0' & c <= '9');
{
morseCode += Integer.parseInt("" + c) + " ";
}
}
JOptionPane.showMessageDialog(f, morseCode, "Morse Code", 1);
}
}
Exception in thread "main" java.lang.NumberFormatException: For input string: "H"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at strings.StringToMorseCodeEncoder.<init>(StringToMorseCodeEncoder.java:22)
at main.Main.starter(Main.java:108)
at main.Main.main(Main.java:31)
Anscheinend ergeben beide Bedingungen in der if-Bedingung true, obwohl 'H' größer '9' ist. Was mache ich falsch?