Page 369 - ComputerScience_Class_11
P. 369
6 int array[ ] = new int[4];
7 for(i = 0; i<4; i++)
8 {
9 f = f*(i+1);
10 array[i] = f;
11 }
12 for(i=0; i<4; i++)
13 System.out.println("Factorial of "+(i+1) + ": " + array[i]);
14 }
15 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Factorial of 1: 1
Factorial of 2: 2
Factorial of 3: 6
Factorial of 4: 24
Program 5 Create an array of size 5 and print the largest and the smallest elements in the array.
1 import java.io.*;
2 class LargestAndSmallest
3 {
4 public static void main(String args[]) throws IOException
5 {
6 InputStreamReader isr= new InputStreamReader(System.in);
7 BufferedReader br=new BufferedReader(isr);
8 int number[ ]=new int[5];
9 int i, lar, sma;
10 for(i=0; i<5; i++)
11 {
12 System.out.print("Enter a number: ");
13 number[i]=Integer.parseInt(br.readLine());
14 }
15 lar=number[0];
Arrays 367

