-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray_o2.txt
More file actions
57 lines (46 loc) · 1.47 KB
/
array_o2.txt
File metadata and controls
57 lines (46 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Skapa ett program som ber användaren ange 10 tal. Talen sparas i en array och *efteråt visa högsta och lägsta inmatade värde samt medelvärdet av samtliga inmatningar.
*/
package veck4_o_2_ar;
import java.util.Scanner;
/**
*
* @author wiktorialipkowska
*/
public class Veck4_o_2_ar {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int [] result = new int[4]; // how many ing we can add
int [] arr = new int[100]; //max number for input
int sum = 0;
int min = 0;
int max = 0;
Boolean error = false;
int i,temp = 0;
System.out.println("Enter the integers between 1 and 100: ");
//Initialize num[] array with user input
for(i=0; i < result.length; i++){
result[i] = input.nextInt();
//expected input will end when user enters zero
if(result[i] == 0){
break;
}
}//end of for loop
for (i = 0 ; i < result.length; i++){
sum+= result[i];
if (min > result [i]){
min = result[i];
}
if (max < result [i]){
max = result[i];
}
}
double average = (double) sum / result.length;
System.out.printf(" min: " + min);
System.out.printf("%n max: " + max);
System.out.printf("%naverage: %.1f", average);
}//end of main
}//end of CountOccurrenceOfNumbers