-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm.java
More file actions
38 lines (32 loc) · 951 Bytes
/
Copy pathAlgorithm.java
File metadata and controls
38 lines (32 loc) · 951 Bytes
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
package com.example.Algorithm;
public class Algorithm {
public void reverse(String n[]){
for (int i = 0; i <= n.length/2 - 1; i++){
String temp = n[i];
n[i] = n[n.length-1-i];
n[n.length-1-i] = temp;
}
}
public void average(int n[]){
int m = 0;
for (int i = 0; i <= n.length - 1; i++){
m += n[i];
}
m = m / n.length;
System.out.println(m);
}
public void displayStringArray(String n[]){
for(int i = 0; i <= n.length-1; i++){
System.out.print(n[i] + " ");
}
System.out.println();
}
public static void main(String[]args){
Algorithm runner = new Algorithm();
int a[] = {1,2, 3, 4, 5};
String b[] = {"1", "2", "3"};
runner.reverse(b);
runner.displayStringArray(b);
runner.average(a);
}
}