package ch7;
import java.io.*;
public class ch7_5_2 
{
    public static void main(String awgs[])throws IOException
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader buf=new BufferedReader(in);
        int num[]=new int[12];
        int x,a,b=0,c;
        String sc;
        for (x=0;x<=11;x++)
        {
            num[x]=(int)(Math.random()*2);
            System.out.print(num[x]+",");
        }
        System.out.println();
        do 
        {
            System.out.println("Enter the number u wanna check 1~12");
            sc=buf.readLine();
            c=Integer.parseInt(sc);
            c=c-1;
            if (num[c]>0)
            {
                System.out.println((c+1)+" is here");
            }
            else
            {
                System.out.println((c+1)+" not here");
            }
        }while(b<=10);
    }
}
 

============

0,0,0,1,1,1,0,0,1,1,0,0,
Enter the number u wanna check 1~12
1
1 not here
Enter the number u wanna check 1~12
2
2 not here
Enter the number u wanna check 1~12
3
3 not here
Enter the number u wanna check 1~12
4
4 is here
Enter the number u wanna check 1~12
5
5 is here
Enter the number u wanna check 1~12
6
6 is here
Enter the number u wanna check 1~12
7
7 not here
Enter the number u wanna check 1~12
8
8 not here
Enter the number u wanna check 1~12
9
9 is here
Enter the number u wanna check 1~12
10
10 is here
Enter the number u wanna check 1~12
11
11 not here
Enter the number u wanna check 1~12
12
12 not here
Enter the number u wanna check 1~12
13
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 12 out of bounds for length 12
    at ch7/ch7.ch7_5_2.main(ch7_5_2.java:24)
 

arrow
arrow
    文章標籤
    JAVA
    全站熱搜
    創作者介紹
    創作者 驢子 的頭像
    驢子

    驢子的生活日記

    驢子 發表在 痞客邦 留言(0) 人氣()