JAVA need help creating method removeLongestString
Please go through code and output.
CODE:
import java.util.*;
import java.util.List;
import java.util.Arrays;
public class RemoveLongestString {
public static void
removeLongestString(List<String> listString)
{
int size = 0;
int count = 0;
String temp = "";
for(int i=0;
i<listString.size(); i++) // check max length and register it
with count
{
temp =
listString.get(i);
if(size <
temp.length())
{
size = temp.length();
count = i;
}
}
listString.remove(count); // remove
max length string
}
public static void main(String[] args)
{
List<String> listString = new
ArrayList<String>();
listString.clear();
listString.add("three");
listString.add("four");
removeLongestString(listString);
System.out.println(listString);
}
}
OUTPUT:
JAVA need help creating method removeLongestString List<String> listString = new ArrayList<String> ; listString.clear ; 1istString.add ("three")...
Consider the following code segment. ArrayList<String> towns = new ArrayList<String> (); towns.add("Baltimore"); towns.add("Bethesda"); towns.add("Wheaton"); towns.add("Greenbelt"); towns.add("Rockville"); for (int k = 1; k< towns.size(); k ++) System.out.print(towns.get(k) + " "); What is printed as a result of executing the code segment? Baltimore Bethesda Wheaton Greenbelt IndexOutOfBoundsException message Baltimore Bethesda Wheaton Greenbelt Rockville Bethesda Wheaton Greenbelt Rockville Refer to the doSomething method: public static void doSomething (ArrayList list, int i, intj) SomeType temp = list.get(i); list.set(i, list.get()); list.set(j, temp); Which best describes...
Consider the following Java method: public static ArrayList<Integer nums ArrayList<Integer values new ArrayList<Integer0; for(int i=10; i<30; i-i+3) if(i%) values.add(i); return values: What is returned after the method call nums()? a. [12] b. [13] c. [14] d. [15] e. [16] O Which of the following represents the final output of the code segment below? int k: int[]A; A new int[3]: fork-0; k<A.length;k++) A[k]-A.length-k; forſk-0; k<A.length-1; k++) A[k+1]-A[k) for(int i-0;i<A.length;i++) System.out.print(A[i]+" "); a. 222 O b. 333 c. 444 d. 555 O...
question 27’s end is in the next page 24 Suppose you have created a list using the statement ArrayList String> NYIT CS Courses new ArrayList(31 What would java do when you try to insert more than 31 courses? ANS: LinelI) check one with x: continue process as usual I Ijava automatically expand array space you manually expand more array spaces 25 Suppose NYIT CS COurscs is an object of the class Array List Suring Write Java statements that will display...
Need help with this. Java please! Write a recursive method that counts the number of bowling pins given the number of pins in the back row: 1. public static int numPins (int num) numPins(0)-> 0 numPins(1) → 1 numPins(2)-> 3
Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int k = n; k > 0; k--) seq.add(new Integer(k+3)); return seq What is the final output of the following Java statement? System.out.println(mystery(3)); a. [1,2,4,5) b. [2,3,4,5) c. [6,5,4,3] d. [7, 7, 8, 8] e. [7,8,9, 8) O Consider the following method: public static int mystery(int[] arr, int k) ifk-0) return 0; }else{ return arr[k - 1] + mystery(arr, k-1):) The code segment below is...
Please explain clearly. Thank you for your time and help will upvote! 6. Suppose a Java method receives a List<Integer> and reverses the order of the items it contains by removing each item from the front of the list and pushing it onto a Stack<Integer), and then popping the items from the stack and inserting each item to the end of the list. What is the expected Big- running time if: a. If an ArrayList is passed. Explain your answer....
Java Do 61a, 61b, 61c, 61d. Show Output and Code. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...
Java - I need help creating a method that removes a node at the specific index position. The * first node is index 0. public boolean delAt(int index) { src code 2 different classes ******************************************** public class Node { private String data; private Node next; public Node(String data, Node next) { this.data = data; this.next = next; } public Node() { } public String getData() { return data; } public void setData(String data) { this.data = data; } public void...
edhesive Term 2 - Unit 5 Week 4 19. Consider the following code segment: ArrayList<Light bulbs - new ArrayList<light> (3 bulbs.add(new Light() bulb, remove (0) bulbs.add(new Light () Light b new Light () bulbs.add(1, b); bulbs.add(new Light()); bulbs.remove(0); bulbs.add(new Light()); bulbs.remove (2); bulbs.add(new Light(); After running the code, what is the size of bulbs? h 3 d 5 20. An ArrayList can hold _ a. Only primitive types b. Both class and primitive types c Only class types d. Only...
in java Part III: Permutations (10 points) Write a recursive method public static ArrayList<int[] > permuteArray (int[] array) that returns an ArrayList of all permutations of the the parameter array. The ArrayList may contain the ar- rays in any order. Example: Suppose array = {4, 7, 1, 2}. Then the ArrayList would contain the following arrays, but in any order: 4 7 12 7 4 1 2 2 1 4 7 1 24 7 4 7 2 1 7 4...