我想知道这个判断用什么语句,,并且举一个例子。
一个数组里有7个元素并且给出要求我们输入一个数字,判断是不是数列里的数。
谢谢大家了·····

解决方案 »

  1.   

    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("没有相同");
    }
    }
      

  2.   


    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("无");
            }   
        }  
    }
      

  3.   

    只有7个元素并且是char或int类型的话用switch也可以的
      

  4.   

    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("无");
            }   
        }  
    }
    嗯这个行