-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_q1.java
More file actions
22 lines (21 loc) · 793 Bytes
/
array_q1.java
File metadata and controls
22 lines (21 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package arrays;
//question: Given an array of students, if the marks of amy student is less than 35 print its roll number.
import java.util.Scanner;
public class array_q1 {
public static void main(String[] args) {
System.out.println("Enter the number of students: ");
Scanner sc = new Scanner(System.in);
int a= sc.nextInt();
int [] arr= new int[a];
System.out.println("Enter marks of the students: ");
for(int i=0; i<a; i++){
arr[i]=sc.nextInt();
}
System.out.println("The roll number of the students whose number is less than 35 are: ");
for(int i=0; i<a; i++){
if(arr[i]<35){
System.out.print(i+" "); // Here the index of the array elements are taken as roll number of the students.
}
}
}
}