1. Write pseudo code that prints the smallest value among a list of numbers. (10 marks)
package list;
import java.util.Scanner;
public class List {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the number of elements of the list");
int n = scan.nextInt();
System.out.printf("Enter %d of the list\n", n);
int [] arr = new int [n];
for(int i=0; i<n; i++){
arr[i] = scan.nextInt();
}
int min = arr[0];
for(int i=0; i<n; i++){
if(arr[i]<min){
min = arr[i];
}
}
System.out.printf("Smallest value in the list is %d\n", min);
}
}
Comments
Leave a comment