【发布时间】:2013-08-13 20:42:05
【问题描述】:
我制作了这个程序来寻找最长的渐进序列。虽然它运行但我收到以下编译时错误: Sequence.java 使用未经检查或不安全的操作。 使用 -Xlint 重新编译:详细信息未选中。
import java.util.Scanner;
import java.util.TreeSet;
public class Sequence
{
public static void main(String [] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the length of the sequence");
int t=s.nextInt();
System.out.println("Enter the elements of the sequence");
int seq[]=new int[t];
TreeSet ans=new TreeSet();
int i,j;
for(i=0;i<seq.length;i++)
{
seq[i]=s.nextInt();
}
for(i=seq.length-1;i>=0;i--)
{
int k=seq[i];
boolean f=true;
for(j=i-1;j>=0;j--)
{
if(k<seq[j])
{
f=false;
}
}
if(f==true)
ans.add(k);
}
Object[] obj=ans.toArray();
for(i=0;i<obj.length;i++)
{
System.out.print(obj[i]+" ");
}
}
}
我该如何纠正我的错误?
【问题讨论】:
-
你需要使用泛型。
-
如果我错了,请纠正我,但我相信此警告是由您致电
nextInt()引起的。如果用户在此处输入除数字以外的任何内容,您的程序将崩溃。 -
@JakeWilson 不,这根本不会产生任何类型的编译错误。
标签: java