Sunday, March 4, 2012

How to deal with Multi-Dimensional Array?


    This program will prompt the user to add information including name,address,and number. Upon every information set was filled, the program will then ask kung gusto pa ng another set:),if  yes ang answer ng user magloloop mula sa simula, but in this program whatever sagot mo basta hindi "no" consider na yes yun. if "no" ang answer, the program will ask the user if she/he wants to have a print of his/her information sets na inilagay?if "yes" ullit, ipiprint ng program yung array na ginawa mo.,If "no",the program will print goodbye and the program will be terminated.

import java.io.*;

public class MultiDimensionalArray {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String name,address,numb,str;
        String[][] strset=new String [100][3];
        int row=0,column=0,ctr=0;
        do{
           System.out.println("name:");
           name= br.readLine();
           strset[row][0]=name;
           System.out.println("from?");
           address=br.readLine();
           strset[row][1]=address;
           System.out.println("number mo:"); 
           numb=br.readLine();
           strset[row][2]=numb;
           System.out.println("do you want to make another transaction?'");
           str=br.readLine();
           row++;
           ctr++;
        }while(!str.equals("no")); 
        
        System.out.println("print?");
        String sagot=br.readLine();
        if ("no".equals(sagot))
            System.out.println("good bye!");
           else if("yes".equals(sagot))
               for(int i=0;i<ctr;i++)
               {
                   System.out.println();
                 for(int j=0;j<strset[i].length;j++)
                
            System.out.println(strset[i][j]);}
             else
                 System.err.println("invalid answer");
    }
}


SHARE and LEARN!

No comments:

Post a Comment