菜鸟的问题!!!在线等!! 我想知道这个判断用什么语句,,并且举一个例子。一个数组里有7个元素并且给出要求我们输入一个数字,判断是不是数列里的数。谢谢大家了····· 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String [] str1= {"1","2","3","4","5","6","7"}; String str2 = "2"; for(int i=0;i<str1.length;i++){ if(str1[i].equals(str2)){ System.out.println("有相同"); break; } if(i==str1.length-1 && !str1[i].equals(str2)){ System.out.println("没有相同"); } } public class SplitDemo { private static int NUM = 4; public static void main(String[] args) { int count = 0; int[] arrNum = {3, 12, 34, 45, 56}; for(int i : arrNum) if(i == NUM) count ++; if(count > 0) { System.out.println("有"); }else{ System.out.println("无"); } } } 只有7个元素并且是char或int类型的话用switch也可以的 public class SplitDemo { private static int NUM = 4; public static void main(String[] args) { int count = 0; int[] arrNum = {3, 12, 34, 45, 56}; for(int i : arrNum) if(i == NUM) count ++; if(count > 0) { System.out.println("有"); }else{ System.out.println("无"); } } }嗯这个行 小程序一枚 Java传参的问题 反射为对象的字段赋值时发生参数错误再求教 LinkedList 的问题 初学者java应该用什么编译软件开发/??? bao110908。。。。。。 老师又出问题了 新手请教 关于getGraphic()返回值的疑问 sun FtpClient.list() 的返回TelnetInputStream 中判断目录文件 关于sin的applet。求解析 图片显示不出来
String str2 = "2";
for(int i=0;i<str1.length;i++){
if(str1[i].equals(str2)){
System.out.println("有相同");
break;
}
if(i==str1.length-1 && !str1[i].equals(str2)){
System.out.println("没有相同");
}
}
public class SplitDemo {
private static int NUM = 4;
public static void main(String[] args)
{
int count = 0;
int[] arrNum = {3, 12, 34, 45, 56};
for(int i : arrNum)
if(i == NUM) count ++;
if(count > 0)
{
System.out.println("有");
}else{
System.out.println("无");
}
}
}
private static int NUM = 4;
public static void main(String[] args)
{
int count = 0;
int[] arrNum = {3, 12, 34, 45, 56};
for(int i : arrNum)
if(i == NUM) count ++;
if(count > 0)
{
System.out.println("有");
}else{
System.out.println("无");
}
}
}
嗯这个行