Question: why is createArrayList the only method getting called. I am trying to call methods such as sortArrayList and maxValue but once I input values, it

why is createArrayList the only method getting called. I am trying to call methods such as sortArrayList and maxValue but once I input values, it just ignores that part (in main) and goes back to createArrayList.

import java.util.ArrayList; import java.util.Scanner; public class CIS231MultiInput { public static void main(String [] args) { ArrayList arrList = sortArrayList(); System.out.println();

System.out.print(" " + sortArrayList() + " "); System.out.println(sortArrayList().size() + " size "); System.out.println("Max value input: " + maxValue(arrList)); }

public static ArrayList createArrayList() { ArrayList values = new ArrayList<>(); Scanner keyIn = new Scanner(System.in);

System.out.println("Enter a line of input with any number of integers"); System.out.println("All values must be white-space-delimited"); System.out.println("Non-integers will be discarded"); System.out.print("->"); String nextLine = keyIn.nextLine();

Scanner lineScan = new Scanner(nextLine);

while (lineScan.hasNext()) { if (lineScan.hasNextInt()) { values.add(lineScan.nextInt()); } else { lineScan.next(); } } System.out.println(" A total of " + values.size() + " integers were input: "); for (Integer next : values) { System.out.print(next + " "); } return values; }

public static ArrayList sortArrayList() { ArrayList someArrayList = createArrayList(); for(int i = 0; i < someArrayList.size() - 1; i++) { int minIndex = i;

for(int j = 1; i < someArrayList.size(); i++) { int temp = someArrayList.get(minIndex); someArrayList.set(minIndex, someArrayList.get(i)); someArrayList.set((i), temp); } } return someArrayList; }

public static int maxValue(ArrayList arrList) { return arrList.get(arrList.size() - 1); } public static int minValue(ArrayList arrList) { return arrList.get(0); } } there is the code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!