how can i find the number of entered sixes with one dimensional array. import java.util.Scanner; import java.util.Arrays; public class TwoDimensionalArrayOfMarks { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter number of Students whose grades you want to store :"); int students=scanner.nextInt(); System.out.print("Enter number of groups of the students :"); int groups=scanner.nextInt(); int grades[][]=new int[groups][students]; System.out.println("Enter "+(students*groups)+" grades: "); for(int row=0;row
how can i find the number of entered sixes with one dimensional array.
import java.util.Scanner;
import java.util.Arrays;
public class TwoDimensionalArrayOfMarks {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of Students whose grades you want to store :");
int students=scanner.nextInt();
System.out.print("Enter number of groups of the students :");
int groups=scanner.nextInt();
int grades[][]=new int[groups][students];
System.out.println("Enter "+(students*groups)+" grades: ");
for(int row=0;row<groups;row++){
for(int col=0;col<students;col++ ){
//storing student's grades
grades[row][col]=scanner.nextInt();
}
}
System.out.println("Student Grades");
for(int row=0;row<groups;row++){
System.out.print("Group"+(row+1)+" ");
for(int col=0;col<students;col++ ){
System.out.print(grades[row][col]+" ");
}
System.out.println();
}
// calculating grades of 6 ??
Introduction of Program:
The Java Program takes numbers of students and number of groups as input from the user and then the user enters the grades out of 10 and then the program calculates the number of grades of 6 entered in the given grades and stored that grades 6 in the one-dimensional array and then displays it.
Source code of the Program: save the below code as TwoDimensionalArrayOfMarks.java
import java.util.Scanner;
import java.util.Arrays;
public class TwoDimensionalArrayOfMarks {
public static void main(String[] args)
{
//scanner class to take user input
Scanner scanner=new Scanner(System.in);
System.out.print("Enter number of Students whose grades you want to store :");
//taking number of students from rhe user
int students=scanner.nextInt();
System.out.print("Enter number of groups of the students :");
//taking number of groups from the user
int groups=scanner.nextInt();
//declaring 2-D array
int grades[][]=new int[groups][students];
System.out.println("Enter "+(students*groups)+" grades out of 10.");
for(int row=0;row<groups;row++){
for(int col=0;col<students;col++ ){
//storing student's grades in 2-D array
grades[row][col]=scanner.nextInt();
}
}
//Displaying grades
System.out.println(" Student Grades");
for(int row=0;row<groups;row++){
System.out.print("Group"+(row+1)+" ");
for(int col=0;col<students;col++ ){
System.out.print(grades[row][col]+" ");
}
System.out.println();
}
//calculating grades 6 and displaying the data
int arr[]=new int[50];
int i=0;
System.out.println();
for(int row=0;row<groups;row++){
for(int col=0;col<students;col++ ){
if(grades[row][col]==6){
System.out.println("Student "+(col+1)+" in the Group"+(row+1)+" has sixes.");
//storing the grades of 6 in the one dimensional arraay
arr[i]=grades[row][col];
i++;
}
}
}
System.out.println();
System.out.println("Number of 6 in the given Grades : "+i);
System.out.println("One dimesional array that stores sixes :");
for(int j=0;j<i;j++){
System.out.print(arr[j]+" ");
}
System.out.println();
}
}
Step by step
Solved in 3 steps with 1 images