-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRepeatStructure.java
More file actions
56 lines (45 loc) · 1.92 KB
/
RepeatStructure.java
File metadata and controls
56 lines (45 loc) · 1.92 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package example.oo.main;
public class RepeatStructure {
public static void main(String args[]){
//array declaration
float[] unidimensionalVariable= {5.6f, 7.8f, 6.4f, 4.3f, 7.2f};
byte i=0;
while(i<unidimensionalVariable.length){
System.out.println("WHILE: Element at index "+ i +" is "+unidimensionalVariable[i]);
i++;
}
i=0;
do{
System.out.println("DO-WHILE: Element at index "+ i +" is "+unidimensionalVariable[i]);
i++;
}while(i<unidimensionalVariable.length);
//reading all elements of this array
for(i=0;i<unidimensionalVariable.length;i++){
System.out.println("FOR: Element at index "+ i +" is "+unidimensionalVariable[i]);
}
//calculating sum
float sum=0;
for(i=0;i<unidimensionalVariable.length;i++){
sum+=unidimensionalVariable[i];
}
System.out.println("The sum of all array elements is:"+ sum);
//calculation the avarage
float average=sum/unidimensionalVariable.length;
System.out.println("The average of elements is:"+ average);
float variance=0;
i=0;
while(i<unidimensionalVariable.length){
float distanceFromAverage=unidimensionalVariable[i]-average;
variance+=Math.pow(distanceFromAverage, 2);
i++;
}
System.out.println("The variance of elements is:"+ variance);
double standardDeviation=Math.sqrt(variance);
System.out.println("The standard deviation of elements is:"+ standardDeviation);
}
}