-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayFront9.java
More file actions
30 lines (29 loc) · 795 Bytes
/
Copy pathArrayFront9.java
File metadata and controls
30 lines (29 loc) · 795 Bytes
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
/*
Given an array of ints, return true if one of the first 4 elements
in the array is a 9. The array length may be less than 4.
*/
package codingbat;
import java.util.Scanner;
public class ArrayFront9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[]= new int[6];
int flag = 0;
System.out.println("Enter the numbers: ");
for (int i = 0; i < 6; i++) {
arr[i] = sc.nextInt();
}
for(int i = 0; i < 4; i++){
if(arr[i] == 9){
flag++;
break;
}
}
if(flag == 1){
System.out.println("True!");
}
else{
System.out.println("False!");
}
}
}