-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExam.java
More file actions
40 lines (40 loc) · 843 Bytes
/
Exam.java
File metadata and controls
40 lines (40 loc) · 843 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
31
32
33
34
35
36
37
38
39
40
import java.util.*;
public class Exam
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a no.");
int n=in.nextInt();
if(n==1){
System.out.println("1\nTotal students seated:1");
return;
}
int arr[][]=new int[n][n];
int count=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if((i+j)%2==0){
arr[i][j]=1;
count++;
}
else
arr[i][j]=0;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==n-1)
System.out.print(arr[i][j]);
else
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println("Total students seated:"+ count);
}
}