-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinear_Search.java
More file actions
24 lines (24 loc) · 864 Bytes
/
Linear_Search.java
File metadata and controls
24 lines (24 loc) · 864 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
package com.java_basics;
import java.util.Scanner;
public class Linear_Search {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr1[] = new int[10];
int sum=0;
for(int i=0;i<arr1.length;i++){
arr1[i] = sc.nextInt();
sum = sum + arr1[i];
}
System.out.println("The sum of all array elements is: "+sum);
int largestNumber = arr1[0];
int smallestNumber = arr1[0];
for(int i=0; i<10 ; i++){
if(arr1[i] > largestNumber)
largestNumber = arr1[i];
else if(arr1[1] < smallestNumber)
smallestNumber = arr1[i];
}
System.out.println("The highest value: "+largestNumber);
System.out.println("The lowest value : "+smallestNumber);
}
}