import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void printIntArray(String name, int[] a) { System.out.printf("%12s: ", name); if (a == null) { System.out.printf("Null array!\n\n"); return; } for (int i = 0; i < a.length; i++) { System.out.printf("%5d", a[i]); } System.out.printf("\n"); } }
File hw5_task8.java contains an incomplete program. Complete that program by defining the following two functions that return the indexes of the grades that are strictly smaller than 60:
selectIndexes_1 function, that returns the indexes as an arrayList of integers.
selectIndexes_1 function, that returns the indexes as an array of integers.
Sample output:
grades: 67 72 93 5 9 54 82 42 84 98 indexesF_AL: [3, 4, 5, 7] indexesF_Arr: 3 4 5 7
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...
import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 { public static void main(String[] args) { String name; String answer; int correct = 0; int incorrect = 0; Scanner phantom = new Scanner(System.in); System.out.println("Hello, What is your name?"); name = phantom.nextLine(); System.out.println("Welcome " + name + "!\n"); System.out.println("My name is Danielle Brandt. " +"This is a quiz program that...
import java.util.ArrayList; import java.util.List; import java.util.Stack; public class Main { public static void main(String[] args) { int programCounter = 0; List<String> program = new ArrayList<String>(); Stack<String> stack = new Stack<String>(); // TODO string probably not best program.add("GOTO start<<1>>"); program.add("LABEL Read"); program.add("LINE -1"); program.add("FUNCTION Read -1 -1"); program.add("READ"); program.add("RETURN "); program.add("LABEL Write"); program.add("LINE -1"); program.add("FUNCTION Write -1 -1"); program.add("FORMAL dummyFormal 0"); program.add("LOAD 0 dummyFormal"); program.add("WRITE"); program.add("RETURN "); program.add("LABEL start<<1>>"); program.add("LINE 1"); program.add("FUNCTION main 1 4"); program.add("LIT 0 i"); program.add("LIT 0 j");...
import java.util.LinkedList; public class testprintOut { private static LinkedList[] array; public static void main(String[] args) { int nelems = 5; array = new LinkedList[nelems]; for (int i = 0; i < nelems; i++) { array[i] = new LinkedList<String>(); } array[0]=["ab"]; System.out.println(array[0]); } } //I want to create array of linked lists so how do I create them and print them out efficiently? //Syntax error on token "=", Expression expected after this token Also, is this how I can put them...
Code in java Using the template below: public class Lab03 { public static void main(String[] args) { ArrayList<Integer> list1 = new ArrayList<Integer>(); Collections.addAll(list1, 1, 3, 5, 5 ); ArrayList<Integer> list2 = new ArrayList<Integer>(); Collections.addAll(list2, 3, 7, 3, 2, 4 ); ArrayList<Integer> result1= uniqueUnion(list1,list2); System.out.println(result1); Integer[] array = new Integer[]{ 29, 28, 27, 16, 15, -14, 3, -2, 2}; ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(array)); System.out.printf("The average is: %.2f%n", averagePositive(arrayList)); } // end main public static ArrayList<Integer> uniqueUnion(ArrayList<Integer> list1, ArrayList<Integer> list2) {...
package week_4; import input.InputUtils; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Random; import static input.InputUtils.positiveIntInput; import static input.InputUtils.yesNoInput; /** Write a program to roll a set of dice. Generate a random number between 1 and 6 for each dice to be rolled, and save the values in an ArrayList. Display the total of all the dice rolled. In some games, rolling the same number on all dice has a special meaning. In your program, check if all dice have the same value,...
Question 2: Execute the following program. import java.util.Arrays; public class ArrayManipulations { public static void main(String[] args) { // sort doubleArray into ascending order char [] A = {'g', ', 'y', 'a', 'e','d' }; Arrays.sort( A); for (char value: A) System.out.printf("%2C", value); System.out.printf("\n"); char [] A Copy = new char[ 3 ]; System.arraycopy( A, 2, A Copy, 0, A Copy.length); for(char value: A Copy) System.out.printf("%2C", value); System.out.printf("\n"); int location = Arrays.binary Search(A Copy, 'y'); if(location >=0) System.out.printf("y Found at element...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null; //TODO...
import java.util.*; public class PairFinder { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Read in the value of k int k = Integer.parseInt(sc.nextLine()); // Read in the list of numbers int[] numbers; String input = sc.nextLine(); if (input.equals("")) { numbers = new int[0]; } else { String[] numberStrings = input.split(" "); numbers = new int[numberStrings.length]; for (int i = 0; i < numberStrings.length; i++) { numbers[i] = Integer.parseInt(numberStrings[i]); } } System.out.println(findPairs(numbers, k)); } //method that...
What does this program print? package javaapplication210; public class JavaApplication210 { public static void main(String[]args){ System.out.printf("Result is: % d/n", mystery (-5, -9));//System.out.printf("Result is: % d/n", mystery (-4, -8));//System.out.printf("Result is: % d/n", mystery (-6, -7));//} public static int mystery(int a, int b) { if(b - 1) returns a; else return a + mystery(a, b + 1); } }
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null;...