Page 331 - ComputerScience_Class_11
P. 331
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
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 Java program 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);
Arrays 329

