[英]unchecked or unsafe operation error
I have made this program for finding the Longest progressive sequence. 我制作了这个程序来查找最长的渐进序列。 Though it runs but I am getting the following compile time error: Sequence.java uses unchecked or unsafe operations.
尽管它运行,但出现以下编译时错误:Sequence.java使用未经检查或不安全的操作。 Recompile with -Xlint:unchecked for details.
使用-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]+" ");
}
}
}
How do I rectify my mistake? 我该如何纠正我的错误?
TreeSet is a generic Class. TreeSet是一个通用类。 You need to give it a type.
您需要给它一个类型。 It looks like you're adding
ints
into it, so the correct declaration would be 好像您要向其中添加
ints
,因此正确的声明应为
TreeSet<Integer> ans = new TreeSet<>();
or, in pre Java7 versions, 或者,在Java7之前的版本中,
TreeSet<Integer> ans = new TreeSet<Integer>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.