Page 470 - CA_Blue( J )_Class10
P. 470
23 }
24 if(pos==-1) // Checking if number is there in the array
25 {
26 System.out.println("Search element not found");
27 }
28 else
29 {
30 System.out.println(n + " found at position " + pos);
31 }
32 } // End of main()
33 } // End of class
Output
Enter number to search: 25
25 found at position 3
Enter number to search: 45
Search element not found
Variable Description
NAME DATATYPE DESCRIPTION
arr[] int[] Array to store given numbers
n int Number to check
min int Minimum position
max int Maximum position
mid int Middle position
pos int Position when searched element is found
(d) Programs on Double dimensional arrays as given in the scope of the syllabus.
Write a program to accept numbers into an array of size 4X4. Then display the diagonals and also
Program 12
display the sum of numbers present in the diagonal position.
1 import java.util.*; //importing package "util"
2 class diagonal //Declaration of class
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int a[][] = new int[4][4]; // Declaration of array
468468 Touchpad Computer Applications-X

