Question
The code below sorts a poset of ints from user input based on divisibility. it is also supposed to print the minimal and maximal elements
The code below sorts a poset of ints from user input based on divisibility. it is also supposed to print the minimal and maximal elements of the poset but i am not sure how to find them. Any help would be appreciated!
package selectionsort; import java.util.Scanner; /** * * @author jharr149 */ public class SelectionSort {
public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter number of positive integers:"); int total = scan.nextInt(); System.out.println("Now enter " + total + " positive integers"); int [] arr = new int[total]; for (int i = 0; i < arr.length; i++) { int input = scan.nextInt(); if(input < 0){ System.out.println("That is not a positive integer, try again."); i--; } else arr[i] = input; } System.out.println("Your array before sort:"); printArr(arr); System.out.println(""); sortArr(arr); System.out.println("After sort:"); printArr(arr); min(arr); max(arr); } public static void sortArr(int[] arr){ int min; int temp; for(int i=0; i < arr.length; i++){ min = i; for(int j = min + 1; j
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started