I'm trying to make a program to analyze data, but the amount of data changes each time. Here is an example output:
Please enter the sample size: 3
Enter numbers for Trial 0
Enter sample #0:50
Enter sample #1:49
Enter sample #2:51
Enter numbers for Trial 1
Enter sample #0:30
Enter sample #1:31
Enter sample #2:32
Enter numbers for Trial 2
Enter sample #0:25
Enter sample #1:26
Enter sample #2:27
Enter numbers for Trial 3
Enter sample #0:15
Enter sample #1:16
Enter sample #2:17
Sample # Trial 1 Trial 2 Trial 3 Trial 4
0 50 30 25 15
1 49 31 26 16
2 51 32 27 17
-------------------------------------------------------
Average: 50 31 26 16
Min Average: 16
Max Average: 50
The trials do NOT concur!
This is the code I have currently:
import java.util.Scanner;
public class DataAnalyze {
public static void main(String[] args) {
int sample = 0;
int avg;
int t1 = 0;
int t2;
int t3;
int t4;
int val;
int max;
int min;
Scanner input = new Scanner(System. in );
System.out.println("Please enter the sample size: ");
sample = input.nextInt();
System.out.println("Enter the numbers for Trial 0");
for (int i = 0; i < sample; i++) {
System.out.println("Enter sample # " + i + " : ");
t1 = input.nextInt();
}
System.out.println("\tSample #\tTrial 1\tTrial 2\tTrial 3\tTrial 4");
System.out.println("\t" + (sample - 1) + "\t" + t1);
}
}
I guess what I'm asking is how to make the for loop collect the input for t1 the first time around, t2 the second time around, and t3 the third time around, etc. Basically, how do I change what input a value is being assigned to each time the loop iterates? I assume that some sort of array is the best way, but I'm not well versed in java so if you could provide me an example that would be great, thanks.