Skip to content

Commit 792900f

Browse files
committed
For loop practice.
Signed-off-by: Someshdiwan <[email protected]>
1 parent aba563f commit 792900f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)