Please help me about this array Program code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • randy18h
    New Member
    • Jan 2010
    • 1

    Please help me about this array Program code

    Output:
    Enter a Value: //x6
    Menu
    1. Search
    2. Locate for an index
    Choice:

    //if chosen 1: sample//
    Enter a value to search: 6
    6
    //else if not available//
    Number not found

    //if chosen 2: sample//
    Enter a value to search index: 6
    //else if not available//
    Number not found

    //here is my program code//
    import java.util.Scann er;
    public class Program1
    {
    public static void main(String[]args){
    Scanner read=new Scanner(System. in);
    int num[][], r, c, a, e;
    num=new int[2][3];
    for(r=0; r<=1; r++)
    {
    for(c=0; c<=2; c++)
    {
    System.out.prin t("Enter a value: ");
    num[r][c]=read.nextInt() ;
    }
    }
    System.out.prin tln("Menu");
    System.out.prin tln("1. Search");
    System.out.prin tln("2. Locate for an index");
    System.out.prin t("Choice: ");
    a=read.nextInt( );
    switch(a)
    {
    case 1:
    System.out.prin t("Enter a value to search: ");
    e=read.nextInt( );
    for(int b=0; b<=1; b++)
    {
    for(int d=0; d<=2; d++)
    {
    if(e==num[b][d])
    {
    System.out.prin tln(num[b][d]);
    break;
    }
    }
    }
    System.out.prin tln("Number not found");
    break;
    case 2:
    System.out.prin t("Enter a value to search: ");
    e=read.nextInt( );
    for(int b=0; b<=1; b++)
    {
    for(int d=0; d<=2; d++)
    {
    if(e==num[b][d])
    {
    System.out.prin tln(num[b][d]+" is on index "+b+", "+d);
    break;
    }
    }
    }
    }
    }
    }
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    So what is your specific problem?

    Comment

    Working...