Java编 了个小程序。。提示未经检查或不安全的操作
具体如下注意:SortedArray.java使用了未经检查或不安全的操作。注意:要了解详细信息,请使用-Xlint:unchecked重新编译。代码如下:publicc...
具体如下
注意:SortedArray.java使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用-Xlint:unchecked重新编译。
代码如下:
public class SortedArray
{
public static int indexOf(int[] table,int value)
{
for (int i=0;i<table.length ;i++ )
{
if (table[i]==value)
return i;
}
return -1;
}
public static int indexOf(Comparable[] table,Comparable cobj)
{
if (table!=null&&cobj!=null)
{
for (int i=0;i<table.length&&cobj.compareTo(table[i])>=0 ;i++ )
{System.out.println(table[i]+"?");
if (cobj.compareTo(table[i])==0)
return i;}
}return -1;
}
public static void main(String[] args)
{
String[] keywords={"abstact","boolean","break","byte","case","catch",
"char","class","continue","defuault","do","double","else","extends","false",
"final","finally","float","for","if","implements","import","instanceof","int",
"interace","long","native","new","null","package","private","protected",
"public","return","short","static","super","switch","synchronized","this",
"throw","throws","transient","true","try","void","volatile","while"};
if (args.length>0)
for (int i=0;i<args.length ;i++ )
{
int find=SortedArray.indexOf(keywords,args[i]);
System.out.println(args[i]+((find!=-1)?"":"不")+"是关键字");
}
else
for (int i=0;i<args.length ;i++ )
{
String key="const";
int find=SortedArray.indexOf(keywords,key);
System.out.println(args[i]+((find!=-1)?"":"不")+"是关键字");
}
} }
我试过-Xlint了。。可还是不能用,也搜过一些方法。别人说是泛型。可不知道怎么解决。。求解。谢谢了。。分不多。。贵在求知。。呵呵。。 展开
注意:SortedArray.java使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用-Xlint:unchecked重新编译。
代码如下:
public class SortedArray
{
public static int indexOf(int[] table,int value)
{
for (int i=0;i<table.length ;i++ )
{
if (table[i]==value)
return i;
}
return -1;
}
public static int indexOf(Comparable[] table,Comparable cobj)
{
if (table!=null&&cobj!=null)
{
for (int i=0;i<table.length&&cobj.compareTo(table[i])>=0 ;i++ )
{System.out.println(table[i]+"?");
if (cobj.compareTo(table[i])==0)
return i;}
}return -1;
}
public static void main(String[] args)
{
String[] keywords={"abstact","boolean","break","byte","case","catch",
"char","class","continue","defuault","do","double","else","extends","false",
"final","finally","float","for","if","implements","import","instanceof","int",
"interace","long","native","new","null","package","private","protected",
"public","return","short","static","super","switch","synchronized","this",
"throw","throws","transient","true","try","void","volatile","while"};
if (args.length>0)
for (int i=0;i<args.length ;i++ )
{
int find=SortedArray.indexOf(keywords,args[i]);
System.out.println(args[i]+((find!=-1)?"":"不")+"是关键字");
}
else
for (int i=0;i<args.length ;i++ )
{
String key="const";
int find=SortedArray.indexOf(keywords,key);
System.out.println(args[i]+((find!=-1)?"":"不")+"是关键字");
}
} }
我试过-Xlint了。。可还是不能用,也搜过一些方法。别人说是泛型。可不知道怎么解决。。求解。谢谢了。。分不多。。贵在求知。。呵呵。。 展开
展开全部
//是泛型的问题,加点东西就好了。
public class SortedArray {
public static int indexOf(int[] table, int value) {
for (int i = 0; i < table.length; i++) {
if (table[i] == value)
return i;
}
return -1;
}
//泛型是这样用的 <> Comparable中的类型必须是这个尖括号中的类型
public static int indexOf(Comparable<String>[] table,
Comparable<String> cobj) {
if (table != null && cobj != null) {
for (int i = 0; i < table.length
&& cobj.compareTo((String) table[i]) >= 0; i++) {
System.out.println(table[i] + "?");
if (cobj.compareTo((String) table[i]) == 0)
return i;
}
}
return -1;
}
public static void main(String[] args) {
String[] keywords = { "abstact", "boolean", "break", "byte", "case",
"catch", "char", "class", "continue", "defuault", "do",
"double", "else", "extends", "false", "final", "finally",
"float", "for", "if", "implements", "import", "instanceof",
"int", "interace", "long", "native", "new", "null", "package",
"private", "protected", "public", "return", "short", "static",
"super", "switch", "synchronized", "this", "throw", "throws",
"transient", "true", "try", "void", "volatile", "while" };
if (args.length > 0)
for (int i = 0; i < args.length; i++) {
int find = SortedArray.indexOf(keywords, args[i]);
System.out
.println(args[i] + ((find != -1) ? "" : "不") + "是关键字");
}
else
for (int i = 0; i < args.length; i++) {
String key = "const";
int find = SortedArray.indexOf(keywords, key);
System.out
.println(args[i] + ((find != -1) ? "" : "不") + "是关键字");
}
}
}
public class SortedArray {
public static int indexOf(int[] table, int value) {
for (int i = 0; i < table.length; i++) {
if (table[i] == value)
return i;
}
return -1;
}
//泛型是这样用的 <> Comparable中的类型必须是这个尖括号中的类型
public static int indexOf(Comparable<String>[] table,
Comparable<String> cobj) {
if (table != null && cobj != null) {
for (int i = 0; i < table.length
&& cobj.compareTo((String) table[i]) >= 0; i++) {
System.out.println(table[i] + "?");
if (cobj.compareTo((String) table[i]) == 0)
return i;
}
}
return -1;
}
public static void main(String[] args) {
String[] keywords = { "abstact", "boolean", "break", "byte", "case",
"catch", "char", "class", "continue", "defuault", "do",
"double", "else", "extends", "false", "final", "finally",
"float", "for", "if", "implements", "import", "instanceof",
"int", "interace", "long", "native", "new", "null", "package",
"private", "protected", "public", "return", "short", "static",
"super", "switch", "synchronized", "this", "throw", "throws",
"transient", "true", "try", "void", "volatile", "while" };
if (args.length > 0)
for (int i = 0; i < args.length; i++) {
int find = SortedArray.indexOf(keywords, args[i]);
System.out
.println(args[i] + ((find != -1) ? "" : "不") + "是关键字");
}
else
for (int i = 0; i < args.length; i++) {
String key = "const";
int find = SortedArray.indexOf(keywords, key);
System.out
.println(args[i] + ((find != -1) ? "" : "不") + "是关键字");
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询