forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticefortest.java
More file actions
64 lines (59 loc) · 1.46 KB
/
practicefortest.java
File metadata and controls
64 lines (59 loc) · 1.46 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
57
58
59
60
61
62
63
64
import java.util.ArrayList;
public class practicefortest
{
public static void main(String [] args)
{
int[] arr = {1,2,3,4};
int[][] numbers = {{1,2,3,4}, {10,20,30,40}};
System.out.println(getAverage(arr));
System.out.println(tenOrLarger(arr));
System.out.println(findIt(arr, 2));
System.out.println(largestIndex(arr));
System.out.println(isSorted(arr));
}
public static double getAverage(int[]arr)
{
double average = 0.0;
double total = 0;
for(int i = 0; i<arr.length; i++)
total += arr[i];
average = total/arr.length;
return average;
}
public static int tenOrLarger(int[]arr)
{
int num = 0;
for(int i=0; i<arr.length; i++)
{
if(arr[i]>10)
num = num+1;
}
return num;
}
public static boolean findIt(int[]arr, int n)
{
for(int i=0; i<arr.length; i++)
{
if(arr[i]==n)
return true;
}
return false;
}
public static int largestIndex(int[]arr)
{
int highest = arr[0];
for(int i=0; i<arr.length; i++)
if(highest<arr[i])
highest=i;
return highest;
}
public static boolean isSorted(int[]arr)
{
for(int i=0; i<arr.length-1;i++)
{
if(arr[i]>arr[i+1])
return false;
}
return true;
}
}