Skip to main content

Programming using Java Hands On - Arrays | Find & Display the position of a number

 Write a java program to find the given number from the array of elements and display its position. If the number is not present in an array then display it as 0.

Assume the position starts from 1.


Sample Input 1

Enter the array size

4

Enter the values

9

32

17

4

Enter the number to find

17


Sample Output 1

3


Sample Input 2

Enter the array size

3

Enter the values

29

53

11

Enter the number to find

49


Sample Output 2

0

Write a java program to find the given number from the array of elements and display its position. If the number is not present in an array then display it as 0.  Assume the position starts from 1.   Sample Input 1  Enter the array size  4  Enter the values  9  32  17  4  Enter the number to find  17   Sample Output 1  3   Sample Input 2  Enter the array size  3  Enter the values  29  53  11  Enter the number to find  49   Sample Output 2  0


Result Description


Summary of tests
*Note: All the test cases might not have same weightage
+------------------------------+
|4 tests run / 4 tests passed |
+------------------------------+
TEST CASE PASSED

Comments