帮我看下这个java程序有什么错误?
为什么运行后没有结果?importjava.io.*;importjava.util.*;publicclassZuoye{publicstaticvoidmain(St...
为什么运行后没有结果?
import java.io.*;
import java.util.*;
public class Zuoye
{ public static void main(String args[])
{System.out.println("请输入字符串,以#结尾");
String m[][]={
{"eT","error","error","eT","error","error"},
{"error","eT","error","error","",""},
{"tF","error","error","tF","error","error"},
{"error","","tF*","error","",""},
{"i","error","error",")E(","error","error"}
};
String a[]=new String[50];
Scanner s=new Scanner(System.in);
String ss=s.nextLine();
for(int c=0;c<ss.length();c++)
{a[c]=ss.charAt(c)+"";
if(ss.charAt(c)=='#'){break;}
}
String n="EeTtF";
String t="i+*()#";
String b="#E";
int i=0;
for (int j=0;j<a.length ;j++ )
{ String x=b.charAt(b.length()-1)+"";
int f=t.indexOf(x);
if (f==-1)
{int p=n.indexOf(x);
int q=t.indexOf(a[i]);
if (m[p][q]!="error")
{x=b.substring(0,b.length()-1)+m[p][q];
}else if (m[p][q]=="error")
{System.out.println("出错1");break;
}
}else if (f!=-1)
{if (x==a[i]&&x!="#"&&a[i]!="#")
{b=b.substring(0,b.length()-1);
i=i++;
}else if (x=="#"&&a[i]=="#")
{System.out.println("成功");break;
}else {System.out.println("出错2");break;}
}
}
}
} 展开
import java.io.*;
import java.util.*;
public class Zuoye
{ public static void main(String args[])
{System.out.println("请输入字符串,以#结尾");
String m[][]={
{"eT","error","error","eT","error","error"},
{"error","eT","error","error","",""},
{"tF","error","error","tF","error","error"},
{"error","","tF*","error","",""},
{"i","error","error",")E(","error","error"}
};
String a[]=new String[50];
Scanner s=new Scanner(System.in);
String ss=s.nextLine();
for(int c=0;c<ss.length();c++)
{a[c]=ss.charAt(c)+"";
if(ss.charAt(c)=='#'){break;}
}
String n="EeTtF";
String t="i+*()#";
String b="#E";
int i=0;
for (int j=0;j<a.length ;j++ )
{ String x=b.charAt(b.length()-1)+"";
int f=t.indexOf(x);
if (f==-1)
{int p=n.indexOf(x);
int q=t.indexOf(a[i]);
if (m[p][q]!="error")
{x=b.substring(0,b.length()-1)+m[p][q];
}else if (m[p][q]=="error")
{System.out.println("出错1");break;
}
}else if (f!=-1)
{if (x==a[i]&&x!="#"&&a[i]!="#")
{b=b.substring(0,b.length()-1);
i=i++;
}else if (x=="#"&&a[i]=="#")
{System.out.println("成功");break;
}else {System.out.println("出错2");break;}
}
}
}
} 展开
展开全部
int q = t.indexOf(a[i]);
这句,必须保证你输入的字符串每一个字母都在 t字符串中,才能使q不会返回-1,否则下一句
m[p][q]肯定报错
这程序所有变量都一个字母,各种b4
这句,必须保证你输入的字符串每一个字母都在 t字符串中,才能使q不会返回-1,否则下一句
m[p][q]肯定报错
这程序所有变量都一个字母,各种b4
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
正确程序如下:
package com.jdbc;
import java.io.*;
import java.util.*;
public class Zuoye {
public static void main(String args[]) {
System.out.println("请输入字符串,以#结尾");
String m[][] = { { "eT", "error", "error", "eT", "error", "error" },
{ "error", "eT", "error", "error", "", "" },
{ "tF", "error", "error", "tF", "error", "error" },
{ "error", "", "tF*", "error", "", "" },
{ "i", "error", "error", ")E(", "error", "error" } };
String a[] = new String[50];
Scanner s = new Scanner(System.in);
String ss = s.nextLine();
for (int c = 0; c < ss.length(); c++) {
a[c] = ss.charAt(c) + "";
if (ss.charAt(c) == '#') {
break;
}
}
String n = "EeTtF";
String t = "i+*()#";
String b = "#E";
int i = 0;
for (int j = 0; j < a.length; j++) {
String x = b.charAt(b.length()-2 ) + "";
int f = t.indexOf(x);
if (f == -1) {
int p = n.indexOf(x);
int q = t.indexOf(a[i]);
if (m[p][q] != "error") {
x = b.substring(0, b.length() - 1) + m[p][q];
} else if (m[p][q] == "error") {
System.out.println("出错1");
break;
}
} else if (f != -1) {
if (x == a[i] && x != "#" && a[i] != "#") {
b = b.substring(0, b.length() - 1);
i = i++;
} else if (x == "#" && a[i] == "#") {
System.out.println("成功");
break;
} else {
System.out.println("出错2");
break;
}
}
}
}
}
数组下标越界了。。。
package com.jdbc;
import java.io.*;
import java.util.*;
public class Zuoye {
public static void main(String args[]) {
System.out.println("请输入字符串,以#结尾");
String m[][] = { { "eT", "error", "error", "eT", "error", "error" },
{ "error", "eT", "error", "error", "", "" },
{ "tF", "error", "error", "tF", "error", "error" },
{ "error", "", "tF*", "error", "", "" },
{ "i", "error", "error", ")E(", "error", "error" } };
String a[] = new String[50];
Scanner s = new Scanner(System.in);
String ss = s.nextLine();
for (int c = 0; c < ss.length(); c++) {
a[c] = ss.charAt(c) + "";
if (ss.charAt(c) == '#') {
break;
}
}
String n = "EeTtF";
String t = "i+*()#";
String b = "#E";
int i = 0;
for (int j = 0; j < a.length; j++) {
String x = b.charAt(b.length()-2 ) + "";
int f = t.indexOf(x);
if (f == -1) {
int p = n.indexOf(x);
int q = t.indexOf(a[i]);
if (m[p][q] != "error") {
x = b.substring(0, b.length() - 1) + m[p][q];
} else if (m[p][q] == "error") {
System.out.println("出错1");
break;
}
} else if (f != -1) {
if (x == a[i] && x != "#" && a[i] != "#") {
b = b.substring(0, b.length() - 1);
i = i++;
} else if (x == "#" && a[i] == "#") {
System.out.println("成功");
break;
} else {
System.out.println("出错2");
break;
}
}
}
}
}
数组下标越界了。。。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询