-
Notifications
You must be signed in to change notification settings - Fork 0
/
array1.java
40 lines (30 loc) · 963 Bytes
/
array1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.Scanner;
public class array1 {
public static void main(String[] args) {
// Scanner to take user input
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the number : ");
float num = sc.nextFloat();
// Initializing the array elements
float [] marks = {45.7f, 67.8f, 63.4f, 99.2f,100.0f};
//setting isInArray to false
boolean isInArray = false;
//For each loop to access all the elements in the array and check wether it is there or not
for(float elements:marks){
if(num==elements)
{
isInArray=true;
break;
}
}
//output
if(isInArray)
{
System.out.println("The value is present in the array!");
}
else
{
System.out.println("The value is not present in the array!");
}
}
}