-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCognizant_Q13.java
More file actions
112 lines (86 loc) · 2.12 KB
/
Cognizant_Q13.java
File metadata and controls
112 lines (86 loc) · 2.12 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package technical;
/* Raj wants to know the maximum marks scored by him in each semester. The mark should be between 0 to 100 ,if goes beyond the range display “You have entered invalid mark.”
Sample Input 1:
Enter no of semester:
3
Enter no of subjects in 1 semester:
3
Enter no of subjects in 2 semester:
4
Enter no of subjects in 3 semester:
2
Marks obtained in semester 1:
50
60
70
Marks obtained in semester 2:
90
98
76
67
Marks obtained in semester 3:
89
76
Sample Output 1:
Maximum mark in 1 semester:70
Maximum mark in 2 semester:98
Maximum mark in 3 semester:89
Sample Input 2:
Enter no of semester:
3
Enter no of subjects in 1 semester:
3
Enter no of subjects in 2 semester:
4
Enter no of subjects in 3 semester:
2
Marks obtained in semester 1:
55
67
98
Marks obtained in semester 2:
67
-98
Sample Output 2:
You have entered invalid mark.*/
import java.util.*;
public class Cogni13 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of semester");
int sem_no=sc.nextInt();//number of semester
int sem_sub_no[]=new int[sem_no];
int Max[]=new int[sem_no];
int z=0;
for(int i =0;i<sem_no;i++)
{
System.out.println("Enter the number of subjects in "+ (i+1)+" semester");
sem_sub_no[i]=sc.nextInt();//number of subjects in each semester.
}
for(int i = 0;i<sem_sub_no.length;i++)//loop for initializing the marks[] every time with value from sem_sub_no
{
int marks[]=new int[sem_sub_no[i]];
System.out.println("Enter the marks obtained in "+(i+1)+ " semester");
for(int j =0;j<marks.length;j++)//loop for storing the marks in the array
{
marks[j]=sc.nextInt();
if(marks[j]<0 || marks[j]>100)
{
System.out.println("Invalid Range");
System.exit(0);//terminates the whole program
}
}
int max=marks[0];
for(int k=1;k<marks.length;k++) //loop for storing the max value of marks
{
if(marks[k]>=max)
max=marks[k];
}
Max[z++]=max;
}
for(int i =0;i<Max.length;i++)//printing the max marks
{
System.out.println("Maximum marks is "+ (i+1)+ " semester is "+Max[i]);
}
}
}