File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Section8LoopAB/Loop 2.O/src Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ class LoopsPractice
4+ {
5+ public static void main (String [] args )
6+ {
7+ Scanner sc = new Scanner (System .in );
8+ int n , s , x =0 , pos =0 ;
9+ System .out .println ("Enter size of an array" );
10+ n = sc .nextInt ();
11+ int [] A = new int [n ];
12+ System .out .println ("Enter Array elements:" );
13+
14+ for (int i = 0 ; i <A .length ; i ++)
15+ {
16+ A [i ] = sc .nextInt ();
17+ }
18+ System .out .println ("Array elements are: " );
19+
20+ for (int i = 0 ; i <A .length ; i ++)
21+ {
22+ System .out .println (A [i ]);
23+ }
24+
25+ System .out .println ("Enter element to search: " );
26+ s = sc .nextInt ();
27+
28+ for (int i = 0 ; i <A .length ; i ++)
29+ {
30+ if (A [i ] == s )
31+ {
32+ x = 1 ;
33+ pos = i ;
34+ break ;
35+ }
36+ }
37+ if (x == 0 )
38+ {
39+ System .out .println ("not found" );
40+ }
41+ else
42+ {
43+ System .out .println ("Found at " +pos );
44+ }
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments