我正在尝试做一个莫尔斯电码-英语双向翻译
import java.util.Scanner;
public class JavaProject {
public static void main(String[] args) {
// TODO Auto-generated method stub
char [] Eng = { 'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o','p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y' ,'z' };
String [] Code = { ".-" , "-..." , "-.-." , "-.." , "." , "..-." , "--." , "...." , ".." , ".---" , "-.-" , ".-.." , "--" , "-." , "---" , ".--." , "--.-" , ".-." , "..." , "-" , "..-" , "...-" , ".--" , "-..-" , "-.--" , "--.." , "|" };
System.out.println(" Enter Morse Code or something in English. A for english, or B for morse code.");
Scanner a = new Scanner(System.in);
String z = a.nextLine();
if (z.equals("A"));
{
System.out.println("enter in english");
Scanner f = new Scanner(System.in);
String b = f.nextLine();
for ( int x = 0; x < Eng.length; x++ )
{
for ( int y = 0; y < b.length (); y++ )
{
if ( Eng [ x ] == b.charAt ( y ) )
System.out.print ( Code [ x ] + " " );
}
}
}
else if (z.equals("B"));
{
System.out.println("enter in Morse");
Scanner v = new Scanner(System.in);
String n = v.nextLine();
for ( int i = 0; i < Code.length; i++ )
{
for ( int p = 0; p < n.length (); p++ )
{
if ( Eng [ i ] == n.charAt ( p ) )
System.out.print ( Eng [ i ] + " " );
}
}
}
}
}
English to morse 可以完美翻译,但是 else 会导致错误。
另外,我试图做到这一点,所以如果我输入“this”,那么它将转到莫尔斯或英语翻译器,但它似乎不起作用
出于某种原因, else 一词会导致错误