求各路大神帮帮忙,不知道为什么程序一直显示越界?
package shiyan;import java.util.Scanner;
public class qiuzhi {
public static void main(String[] args) {
String a=new String();
int x=0;
stack<Character> stack=new stack<Character>();
System.out.println("请输入:");
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String[] n=new String[100];
for(int i=0;i<str.length();i++){
if(((int)str.charAt(i)>=48 && (int)str.charAt(i)<=57)||str.charAt(i)=='.'){
a=a+Character.toString(str.charAt(i));
if(i==str.length()-1) {
n[x]=a;
}
else {
if(((int)str.charAt(i)<=48 && (int)str.charAt(i)>=57)||str.charAt(i)!='.'){
n[x]=a;
a="";
x=x+1;
}
else {
continue;
}
}
}
else{
if(stack.isempty()){
stack.push(str.charAt(i));
}
else if(str.charAt(i)=='('){
stack.push(str.charAt(i));
}
else if(str.charAt(i)==')'){
while(stack.peek()!='('){
n[x]=Character.toString(stack.peek());
x=x+1;
}
stack.pop();
}
else{
while(panduan.getValue(str.charAt(i))<=panduan.getValue(stack.peek())){
n[x]=Character.toString(stack.peek());
x=x+1;
}
stack.push(str.charAt(i));
}
}
}
while(!stack.isempty()){
n[x]=Character.toString(stack.peek());
x=x+1;
}
for(int i=0;i<x;i++) {
System.out.println(n[i]);
}
}
}
class panduan{
public static int getValue(char b){
int result=0;
switch(b){
case'+':
result=0;
break;
case'-':
result=0;
break;
case'*':
result=0;
break;
case'/':
result=0;
break;
}
return result;
}
}
输出结果
请输入:
1+1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100
at shiyan.qiuzhi.main(qiuzhi.java:53)