Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CalcMode{
  4.  
  5.      public static void main(String []args){
  6.  
  7.                 int[][] array = new int[6][2];
  8.  
  9.                 Scanner input = new Scanner(System.in);
  10.  
  11.                 System.out.print("Please, insert the scores and the frequency of each score:\n");
  12.  
  13.                 int i = 0;
  14.                 while (input.hasNextLine()) {
  15.                         Scanner line = new Scanner(input.nextLine());
  16.  
  17.                         int x = 0;
  18.                         while (line.hasNextInt()) {
  19.                                 array[i][x] = line.nextInt();
  20.                                 x++;
  21.                         }
  22.  
  23.                         i++;
  24.                         if ( i == 6 ) {
  25.                                 break;
  26.                         }
  27.                 }
  28.  
  29.                 int highest = 0;
  30.                 int mode = 0;
  31.                 for( i = 0; i < array.length ; i++ ) {
  32.                         if (array[i][1] > highest) {
  33.                                 highest = array[i][1];
  34.                                 mode = array[i][0];
  35.                         }
  36.                 }
  37.  
  38.                 System.out.println("The mode of students score is " + mode);
  39.  
  40.         }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement