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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 ?? 

Expert Solution
Step 1

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.

Step 2

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();
    }  
}

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education