Page 329 - ComputerScience_Class_11
P. 329

5           {
                   6               Scanner sc= new Scanner(System.in);

                   7               int n;
                   8               System.out.println("Enter the value of n");
                   9               n=sc.nextInt();
                   10              String name[ ]=new String[n];
                   11              char sec[ ]=new char[n];
                   12              int roll[ ]=new int[n];
                   13              int i;
                   14              for(i=0; i<n; i++)

                   15              {
                                        System.out.println("Enter the name, section and roll number of the
                   16                    student");
                   17                  name[i]=sc.next();
                   18                  sec[i]=sc.next().charAt(0);

                   19                  roll[i]=sc.nextInt();
                   20              }
                   21              System.out.println("--------------------------------");
                   22              System.out.println("Name\tSection\tRoll Number");
                   23              for(i=0;i<n;i++)
                   24              {
                   25                  System.out.println(name[i]+"\t"+sec[i]+"\t"+roll[i]);
                   26              }
                   27          }
                   28      }

                 The output of the preceding program is as follows:

                         BlueJ: Terminal Window - Java
                     Options

                    Enter the value of n:
                    2
                    Enter the name, section and roll number of the student
                    Amit
                    A
                    1
                    Enter the name, section and roll number of the student
                    Lalit
                    B
                    2
                    --------------------------------
                    Name  Section  Roll Number
                    Amit   A        1
                    Lalit   B       2




                                                                                                           Arrays  327
   324   325   326   327   328   329   330   331   332   333   334