当前位置: 代码迷 >> Java相关 >> 为什么输入不结果
  详细解决方案

为什么输入不结果

热度:132   发布时间:2006-12-04 01:12:56.0
为什么输入不结果
这个程序是删除输入的字符串中重复的字符:
import java.io.*;
public class test
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String str=in.readLine();
int length=str.length();
char []a=new char[length];

int j=0;
int seat=0;
for(int i=0;i<length;i++)
a[i]=str.charAt(i);
for(int i=0;i<length-1;i++)
{
j=i+1;

while(j<length-1)
{
if(a[i]==a[j])
{
seat=j+1;
for(int m=j;m<length-1;m++)
a[m]=a[m+1];
length--;
}
j=seat;
}




}
for(int i=0;i<length;i++)
System.out.print(a[i]+" ");
System.out.println();
}
catch(IOException e)
{
}

}
}
搜索更多相关的解决方案: 结果  输入  

----------------解决方案--------------------------------------------------------

经过修改之后,可以了,
大家帮忙看一下有什么地方要改进的
import java.io.*;
public class test
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String str=in.readLine();
int length=str.length();
char []a=new char[length];

int j=0;
int seat=0;
for(int i=0;i<length;i++)
a[i]=str.charAt(i);
for(int i=0;i<length-1;i++)
{
j=i+1;
while(j<length)
{
if(a[i]==a[j])
{
for(int m=j;m<length-1;m++)
a[m]=a[m+1];
length--;
j--;
}
j++;

}
}
for(int i=0;i<length;i++)
System.out.print(a[i]+" ");
System.out.println();
}
catch(IOException e)
{
}

}
}


----------------解决方案--------------------------------------------------------
新手,学习中,支持
----------------解决方案--------------------------------------------------------
  相关解决方案