You will be given many coordinates on different lines with -1 as a sentinel. Store the values in an ArrayList, then find the smallest rectangle that can fit all the points inside, and print out the coordinates of the top right and bottom left corners.
Sample input:
-5 16
8 4
1 1
0 0
23 7
1 9
1 -9
3 6
0 2
0 -9
-1
Sample output:
Bottom left corner: (-5, -9)
Top right corner: (23, 16)
I did not finish but here is what i did work on
import java.util.*; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); ArrayList coordArrayListX = new ArrayList(); ArrayList coordArrayListY = new ArrayList(); boolean bob = true; while(bob == true) { System.out.println("Please enter a X value of a coordinate to place in the graph: "); int coordX = scan.nextInt(); coordArrayListX.add(coordX); System.out.println("Please enter a Y value of a coordinate to place in the graph: "); int coordY = scan.nextInt(); coordArrayListY.add(coordY); System.out.println("Continue with the amount of coordinates?(yes or no): "); String question = scan.next(); if (question.equals("yes")){ bob = false; } else{ bob = true; } } int[] coordListX = coordListXArray.toArray(); int[] coordListY = coordListYArray.toArray(); int smallestX = 0; System.out.println("Here is the list of coordinates!: "); //will delete later System.out.println(coordListX); System.out.println(coordListY); int coordListXLength = coordListX.length; int a=0; while(a<coordListXLength){ smallestX = coordList[0]; nextNum = coordListX[a]; a++; if (nextNum < smallestX){ smallestX = nextNum; } else{ continue; } System.out.println(smallestX); } } }