class Excep { public static void main(String[] args){ try{ int arr[]=(1,2}; int x = arr[1]/arr[0]-1; catch(ArithmeticException e) { System.out.println("divide by 0"); catch(ArrayIndexOutofBoundsException e)
Q: public class Selection { public static void sort(Comparable[] a) int N = a.length; for (int i = 0; i…
A: Coding
Q: TRUCTION: make this a flowchart import java.util.HashSet; import java.util.Set; public class…
A: Flowchart for the given code with output given below.
Q: figure out the time complexity of the each method you wrot
A: To find complexity of methods in the Using class
Q: public static void question(ArrayStack s1, ArrayStack s2) { if(s1.isEmpty()…
A: s2 will contain the alternate elements of s1 in the reverse order
Q: Write a short recursive Java method that rearranges an array of integer values so that all the even…
A: The complete code is given below with the output.
Q: What does this method do? public class StackTest { public static void question(ArrayStack s1,…
A: - The question wants to know what does this code does. - The code is using two arraystacks and the…
Q: sortLecNotes sortsearchassigncodeex1.java sort, search for a specific student package…
A: Answer: our instruction is answer the first three part from the first part and . I have done code in…
Q: (Recursive Binary Search) Write a recursive method RecursiveBinarySearch to perform a binary search…
A: Answer: RecursiveBinarySearch () This method takes four arguments the array, value to search, left…
Q: public class RecursiveMerge Sort { //This can be used to test your implementation. public static…
A: Merge Sort - Merge Sort is a divide and conquers algorithm. In the merge sort algorithm, the input…
Q: public class Soru2 { static void sort(char a[]) { for(int i = 0; i < a.length;…
A: So, Here we are given code of soring and we have calculate the time complexity and number of steps.…
Q: I keep getting Java null point exception for makeMovielist
A: import java.util.ArrayList; import java.util.Arrays; public class MovieList { /** * This method…
Q: Write a method that resizes an array based queue to be exactly the size of the data it contains.…
A: Program Explanation: Import the exception class Define a class for queue Declare the attributes for…
Q: My Arrays.sort is not printing out sorted array ints. It prints out an unsorted list.
A: In the above program you are passing copyArr.length-1 as to index.
Q: public class elements { public static void main(String args[]) { Scanner sc = new…
A: A flowchart is nothing but the pictorial representation of the sequence of steps in a program. It…
Q: Write a java method to search for an element in an array using a linear search. Many list processing…
A: Use a recursive function which accepts 4 parameters, one is the list, second is the search value,…
Q: java The search method accepts ArrayList of Strings and String find. The method returns a String.…
A: The java code for this problem is given below. Open any java code editor and run the program. Input:…
Q: Complete the isPalindrome method to recursively determine whether the parameter str is a palindrome.…
A: Question Complete the isPalindrome: import java.util.*; public class PalindromeDetector{…
Q: java program : Assume the following method is added to the ArrayStack class. What does this method…
A: in for loop, the increment is of 2 which means i is incremented by 2 each time program is not…
Q: The language used here is in Java. Please answer the question in the screenshot. Please use the code…
A: Coded in Java.
Q: Please write missing statements to make the following method buildMap complete. The buildMap method…
A: If you clearly observe this the key we are going to map a Book object is same as that of ISBN number…
Q: public class Selection { public static void sort(Comparable[] a) int N = a.length; for (int i = 0; i…
A: 1. Explain the code line by line: public class Selection{ public static void main(Comparable [] a)…
Q: import java.util.*; class JavaGenericsTest{ public static void main(String args[]) { ArrayList…
A: Output of the above java code with ArrayList
Q: uestion 4. Recursion write a Java program. A perfect number is a number whose factors, excluding…
A: Import scanner class. Define Main class. Define main function. Define int variable num and sum.…
Q: def count_vowels(self, a_string): """ Given a string, count the number of vowels one character at a…
A: Please find the answer below:
Q: Create a Java class Recursive Methods.java and create the following methods inside: ALL THE METHODS…
A: Answer: Algorithm: 1. we have create class as RecursiveMethods 2. we have create a method…
Q: Write the following method that shuffles an ArrayList:public static <E> void…
A: Method: //shuffle method static void shuffle(ArrayList<Number> list) {…
Q: package edu.luc.cs.cs271.mazesolver; import java.util.ArrayList; import java.util.Scanner; public…
A: File: maze.py Project 7.9 Determine the solution to a maze problem. Uses a gid to represent…
Q: public class QueueEx public static void method1(ArrayQueue q1, ArrayQueue q2) { Iterator iter1 =…
A: Required: java
Q: What does this method do? public class StackTest public static void question(ArrayStack s1,…
A: Dear Student, Based on your program, first the result of last element in s1 will be stored in s2…
Q: import java.util.ArrayList; import java.util.List; public class RemoveZeroes { public static…
A: ArrayList is the class of java.util package. The ArrayList is a generic data type that can take…
Q: Write a recursive method that displays all permutations of a given array ofintegers. Here is a…
A: Programming language is missing in the question. So we will answer the given criteria in Java…
Q: CONVERT this code into C language. Thanks .............. import java.util.*; public class Anagram…
A: Solution:-- 1)The given question has required for the solution which is been expected to be…
Q: Consider the interface below: import java.util.NoSuchElementException; public interface MyList {…
A: Here we have given the code in java for the questions asked. you can find the solution in step 2.
Q: Write a static method public static char[] filter(char[] list, char target) The method will take an…
A: The program is written in Java. Check the program screenshot for the correct indentation. Please…
Q: Computer Science create a method +addToList(o:E):void that adds the object (o) to the ArrayList…
A: import java.util.*; is used in the following program it allows us to add or remove objects.…
Q: Write a method public static void insert(int[] a, int n, int x) that inserts x in…
A: Insertion Sort are the simple algorithm that works like the manner in which you sort playing a card…
Q: Analyse the following code: public class Test { public static void main(String[] args) {…
A: Required: Analyse the given code:
Q: InfoProcessorTest.java import java.util.*; /** * * Class to process and extract information…
A: The Java code implementation for the program is given in the below step.
Q: create a recursive decent parse that read ( 1 + 2 ) / 3 from a txt file import java.io.File; import…
A: public class KeywordSearch{//method for searching the keywordpublic void search(String keyword)…
Q: java program : Assume the following method is added to the ArrayStack class. What does this method…
A: Given:- java program : Assume the following method is added to the ArrayStack class. What does…
Q: sortsearchassigncodeex1.java sort, search for a specific student package…
A: If the input array is not sorted, the results are undefined and negative. If there are duplicates,…
Q: ix the code below so that there is a function that calculate the height of the triangle.
A: // Sierpinski.java public class Sierpinski { // method to find the height of an equilateral…
Q: b. import java.util.ArrayList; public class Main { public static void main (String[]args) {…
A: - We have to talk for the ArrayList and get the output of the program. - In the program, we have…
Q: import java.util.LinkedList; import java.util.Scanner; import java.util.Arrays; import java.io.File;…
A: import java.util.LinkedList;import java.util.Scanner;import java.util.Arrays;import…
Q: import java.util.*; public class Print { public static void main(String args[]) { List…
A: Above code is showing adding elements into the list. As per the comments , its asking to sort the…
Q: Consider the interface below: import java.util.NoSuchElementException; public interface MyList {…
A: The answer for the above mentioned question is given in the below steps for your reference.
Q: NameSorter.java Name.java import java.util.Scanner; import java.util.ArrayList; import…
A: code: import java.util.*;public class Main{ public static void main(String[] args) { Scanner scnr =…
Step by step
Solved in 2 steps with 1 images
- public class ShoppingListDriver{ public static void main(String[] args){ ShoppingList sl=new ShoppingList(3);sl.insert(null);sl.insert(new Item("Bread", "Carb Food", 2, 2.99));sl.insert(new Item("Seafood","Sea Food", -1, 10.99));sl.insert(new Item("Rice", "Carb Food",2, 19.99));sl.insert(new Item("Salad Dressings","Dessing", 2, 19.99));sl.insert(new Item("Eggs", "Protein",2, 3.99));sl.insert(new Item("Cheese","Protein", 2, 1.59));sl.insert(new Item("Eggs", "Protein",3, 3.99));sl.printNames();sl.print(); System.out.println("After removing Eggs:");sl.remove(new Item("Eggs","Protein",0,0));sl.printNames();sl.print(); }}import java.util.Scanner; public class ContactList { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ContactNode head = null; ContactNode current = null; // Read the name and phone number for three contacts and build a linked list. for (int i = 1; i <= 3; i++) { System.out.print(" " + i + ": "); String name = scnr.next(); System.out.print(" " + i + ": "); String phoneNumber = scnr.next(); ContactNode newContact = new ContactNode(name, phoneNumber); if (head == null) { head = newContact; current = head; } else { current.insertAfter(newContact); current = newContact; } } // Output each contact. current = head; for (int i = 1; current != null; i++) { System.out.print("Person " + i + ": "); current.printContactNode();…public class ArrayMerge { static void arrayMerge(int a[], int b[]){ int c[] = new int[50]; int k = 0; for(int i = 0; i < a.length; i++) { c[k++] = a[i]; } for(int i = 0; i < b.length; i++) { c[k++] = b[i]; } for(int i = 0; i < k; i++) { System.out.println(c[i]); } } public static void main(String[] args) { int a[] = { 18, 36, 41, 78, 56 }; int b[] = { 10, 37, 44 }; arrayMerge(a,b); } } Calculate the algorithm step number and algorithm time complexity of the above program?
- Ex. If the input is: 4 plates 100 spoons 200 cups 150 forks 200 the output is: 200 forks 150 cups 200 spoons 100 plates Inventory.java import java.util.Scanner; public class Inventory {public static void main (String[] args) {Scanner scnr = new Scanner(System.in);InventoryNode headNode;InventoryNode currNode;InventoryNode lastNode; String item;int numberOfItems;int i; // Front of nodes listheadNode = new InventoryNode();lastNode = headNode; int input = scnr.nextInt(); for(i = 0; i < input; i++ ) {item = scnr.next();numberOfItems = scnr.nextInt();currNode = new InventoryNode(item, numberOfItems);currNode.insertAtFront(headNode, currNode);lastNode = currNode;} // Print linked listcurrNode = headNode.getNext();while (currNode != null) {currNode.printNodeData();currNode = currNode.getNext();}}} InventoryNode.java public class InventoryNode {private String item;private int numberOfItems;private InventoryNode nextNodeRef; // Reference to the next node public InventoryNode()…Complete the method loadBuses(String bfile) that reads information bus information from afile (bfile contains the filename) . Each row in the file should trigger the creation of aninstance of bus or an appropriate subclass, according to the data in table 1. All buses createdshould be added to an arraylist. LoadBuses should return the populated arraylist. public ArrayList<Bus> loadBuses(String bfile ) { Scanner bscan = null; ArrayList<Bus> blist = new ArrayList<Bus>(); return blist; }JAVA PROGRAMMING I need an expert to write Test application to run the MyArrayStack<T> class. import java.util.Arrays; interface MyStack<T> {public void push(T o);public T pop() throws StackEmptyException;public T peek();public boolean isEmpty();public int size();} class MyArrayStack<T> implements MyStack<T>{private static final int DEFAULT_STACK_SIZE = 100;T[] stackArray;int top = 0; public MyArrayStack() {this(DEFAULT_STACK_SIZE);}public MyArrayStack(int defaultSize) {top = 0;stackArray = (T[])new Object[defaultSize];} public void push(T o) {if (size() == stackArray.length) expandCapacity();stackArray[top] = o;top++;}private void expandCapacity() {stackArray = Arrays.copyOf(stackArray, stackArray.length*2);System.out.println("StackArray size is automatically expanded:" + stackArray.length);} public T pop() throws StackEmptyException {if (isEmpty()) throw new StackEmptyException("Stack is empty");top--;T o = stackArray[top];stackArray[top] = null;return o;}…
- Rewrite the private static int recurseMax method without using Java API public class Recursion{ public static void main(String[] args){ // My tests (DO NOT MODIFY!) int[] a = {3,2,6,4,15,7,9,8,6}; p(recurseSum(a)); // Sum should be 60 p(recurseMax(a)); // Max should be 15 // End of tests! } // Recursive methods below here... public static int recurseSum(int[] a){ // TODO: This is the wrapper method. You must complete this AND implement helper method int total = recurseSum(a, a.length); return total; } private static int recurseSum(int[] a, int i){ if (i <= 0) return 0; return (recurseSum(a, i - 1) + a[i - 1]); } public static int recurseMax(int[] a){ int max = recurseMax(a, a.length); return max; } private static int recurseMax(int[] a, int i){ if(i == 1) return a[0]; return Math.max(a[i-1], recurseMax(a, i-1)); } //…Beginner Java import java.util.Arrays;import java.util.Scanner; Arrays and scanner required. Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: 100.5 65 pizza 100 45.75 70 5.8 5 Also suppose that you have two integers n and m that are both positive. For example: n = 5 and m = 10 Write a static method: public static double partialSum(Scanner s, int n, int m) that takes a Scanner and two integers n and m as arguments and returns the sum of the integers read by the Scanner that are divisible by n and not divisible by m. In the above example, the integers divisible by 5 and not divisible by 10 are 65 and 5, so the result would be 70. If the Scanner is empty, or no tokens are valid integers, the result should be 0. You can assume the Scanner is not null. It is probably easiest to test your method by creating a Scanner with a String instead of System.in. The starter code for an example of how to do this is…Write an application that displays the strings in the provided array alphabetically in ascending order import java.util.*; public class StringSort { public static void main(String[] args) { String[] values = {"mouse", "dog", "cat", "horse", "cow", "moose", "tiger", "lion", "elephant", "bird", "hamster", "guinea pig", "leopard", "aardvark", "hummingbird"}; } } I need help with this!
- Please make it run out like the EXPECT PICTURES Don’t use try catch // Step 1: Import Java classes Arrays, Random, and Scanner import java.util.Arrays; import java.util.InputMismatchException; import java.util.Random; import java.util.Scanner; /** * A class to generate a random int array then call static * methods to sort and display the array elements. * * Step 2: Enter your name for @author and today's date for @version * @author * @version */ public class StaticMethodApp { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter an integer: "); // Step 3: While the next input token is not an integer // Read the input token // Display a message // Sample message, assuming the input is Java // Not an integer: "Java" // Display the same promt again…For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a comma (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20,30, mport java.util.Scanner; public class Compare { public static void main(String args[]) {final int SIZE_LIST = 4;int[] keysList = new int[SIZE_LIST];int[] itemsList = new int[SIZE_LIST];int i;Scanner input = new Scanner(System.in); keysList[0] = input.nextInt();keysList[1] = input.nextInt();keysList[2] = input.nextInt();keysList[3] = input.nextInt(); itemsList[0] = input.nextInt();itemsList[1] = input.nextInt();itemsList[2] = input.nextInt();itemsList[3] = input.nextInt(); /* Your code goes here */ System.out.println();} }import java.util.Scanner; public class LabProgram { public static Roster getInput(){ /* Reads course title, creates a roster object with the input title. Note that */ /* the course title might have spaces as in "COP 3804" (i.e. use nextLine) */ /* reads input student information one by one, creates a student object */ /* with each input student and adds the student object to the roster object */ /* the input is formatted as in the sample input and is terminated with a "q" */ /* returns the created roster */ /* Type your code here */ } public static void main(String[] args) { Roster course = getInput(); course.display(); course.dislayScores(); }} public class Student { String id; int score; public Student(String id, int score) { /* Student Employee */ /* Type your code here */ } public String getID() { /* returns student's id */…