Page 268 - computer science (868) class 11
P. 268

The output of the preceding program is as follows:
              Enter name of item no: 1 : bag
              Enter cost of item no: 1 : 900

              Enter name of item no: 2 : pen
              Enter cost of item no: 2 : 20
              Enter name of item no: 3 : pencil
              Enter cost of item no: 3 : 10
              Enter name of item no: 4 : copy
              Enter cost of item no: 4 : 90
              Enter name of item no: 5 : book
              Enter cost of item no: 5 : 400

              ------------------------------
              Item Name      Item Price
              bag            900.0
              pen            20.0
              pencil         10.0
              copy           90.0
              book           400.0
              Total price of all items are 1420.0

              Apart from the above two methods, we can also take in the values of the array as parameters. For this, we have to write
              all the values within curly braces in the input window. For example:

              •  String ar[ ]={“India”, “Russia”, “America”, Japan”, “Germany”} - for string type of values.
              •  int ar[ ]={129,5678,3434,54} - for integer values.
              •  double ar[ ]={34.66,67.89,34.67,2.000} - for real value types.

              Let us take a help of a program to understand.



                Program 6      Write a program in Java to input the names and marks of some students and print the total
                               and average marks along with all the names and marks of the students column-wise.

                 1       class name_marks

                 2       {
                 3           public static void main(String stu_name[], int stu_marks[])

                 4           {
                 5               int i, len=0, total_marks=0;

                 6               len = stu_marks.length;
                 7               double avg_marks;

                 8                System.out.println("Total number of students in the class: "+stu_name.
                                  length);
                 9               System.out.println("-------------------------------------------");





                266266  Touchpad Computer Science-XI
   263   264   265   266   267   268   269   270   271   272   273