just in case someone does not know what mode is it is the number that appears most in a set of numbers
The output of the following program is messed up( not just the mode but other parts of it too).
It compiles but the output is not right.
Her is the code:
import javax.swing.*;
public class Array3{
public static void main(String[] args){
double end;
int finish = JOptionPane.YES_OPTION;
do{
int num[]= new int[10];
int mode[] = new int [10];
int numa[] = new int [10];
int y = 0;
int a = 0;
int b = 0;
int c = 0;
boolean ok = false;
for(y = 0; y < 10; y++){
try{
String inputnum = JOptionPane.showInputDialog(null, "Enter a set of ten numbers: \n Enter the numbers one at a time \n They can be negative, positive, even, or odd");
num[y] = Integer.parseInt(inputnum);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "ERROR: Numerical Data Only");
y -= 1;
}
}
num[0] = numa[0];
mode[0]++;
b++;
for(y = 0; y < num.length; y++){
ok = false;
for (c = 0; c < num.length; c++){
if(numa[y] == num [y]){
mode[c] = num[y];
mode[c]++;
ok = true;
}
}
if(ok == false){
num = numa[y];
mode++;
b++;
}
}
String someoutput = "Mode: ";
for(a = 0; a< y; a++){
someoutput += " " + " \n" + num[a] + " " + mode[a];
}
JOptionPane.showMessageDialog(null, someoutput);
end = JOptionPane.showConfirmDialog(null,"Would you like to play again?","Question Box",JOptionPane.YES_NO_OPTION);
}while(end == finish);
Ending.ending();
}
}