
![using System; 3 namespace ConsoleApp2 5 public class Program 7 public static void Main(string] args) int[] tmp,res; :res-Exer](http://img.homeworklib.com/questions/4ea92840-13d1-11ec-b880-f9171ee9f036.png?x-oss-process=image/resize,w_560)

![PrintArray(int[] 67 68 69 70 71 曰: : public static void x,int perLine-20) :: throw new NotImplementedException(); 72 ; public](http://img.homeworklib.com/questions/4f7479d0-13d1-11ec-acd8-e11c282d5e3c.png?x-oss-process=image/resize,w_560)
GetNumber and Getarray parts are working but I need help figuring out part 7_4 and 7_5 (I do not need Printarray). My professor provided the sections in which we need to fill in with code to make them run and pass the test files provides by the professor in Visual Studio.
________________
import java.util.Arrays;
import java.util.Scanner;
public class ArraySequence {
public static void main(String[] args) {
int[] a = GetArray();
System.out.print("Printing array: ");PrintArray(a);
int[] longestArray = Excercise7_4(a);
System.out.print("\nLongest sequence:
");PrintArray(longestArray);
}
public static int[] GetArray() {
Scanner scanner = new Scanner(System.in);
System.out.print("How many numbers you want in the array: ");
int arraySize = scanner.nextInt();
int[] numbers = new int[arraySize];
for (int count = 1; count <= arraySize; count++) {
System.out.print("Enter number: ");
numbers[count - 1] = scanner.nextInt();
}
return numbers;
}
public static void PrintArray(int[] array) {
int perLine = 20;
int index = 0;
for (int num : array) {
if (index % perLine == 0) {
System.out.println();
}
System.out.print(num + " ");
index += 1;
}
}
public static int[] Excercise7_4(int[] x) {
int previousElement = x[0];
int previousCount = 1;
int currentElement = x[0];
int currentCount = 1;
for (int index = 0; index < x.length - 1; index++) {
if (x[index] == x[index + 1]) {
currentCount += 1;
currentElement = x[index];
} else {
if (currentCount > previousCount) {
previousElement = currentElement;
previousCount = currentCount;
} else if (currentCount == previousCount && currentElement
> previousElement) {
previousElement = currentElement;
previousCount = currentCount;
}
currentCount = 1;
currentElement = x[index + 1];
}
}
if(currentCount>previousCount){
previousElement=currentElement;
previousCount=currentCount;
}
if(previousCount==1 &&
previousElement<x[x.length-1]){
previousElement=x[x.length-1];
}
int[] newArray = new int[previousCount];
Arrays.fill(newArray, previousElement);
return newArray;
}
}
GetNumber and Getarray parts are working but I need help figuring out part 7_4 and 7_5...
I need a java flowchart for the following code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter the input size: "); int n=sc.nextInt(); int arr[]=new int[n]; System.out.print("Enter the sequence: "); for(int i=0;i<n;i++) arr[i]=sc.nextInt(); if(isConsecutiveFour(arr)) { System.out.print("yes the array contain consecutive number:"); for(int i=0;i<n;i++) System.out.print(arr[i]+" "); ...
PrintArray vi Create a class called PrintArray. This is the class that contains the main method. Your program must print each of the elements of the array of ints called aa on a separate line (see examples). The method getArray (included in the starter code) reads integers from input and returns them in an array of ints. Use the following starter code: //for this program Arrays.toString(array) is forbidden import java.util.Scanner; public class PrintArray { static Scanner in = new Scanner(System.in);...
Need help with this binary tree program. I will give a thumbs up for anybody who helps. Source Code: import java.util.Random; import java.util.Scanner; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class Trees { public static int[] prepareData(int[] data){ /* Data is prepared by inserting random values between 1 and data.length. Data items may be assumed to be unique. Please refer to lab spec for the problem definiton. */ ArrayList list = new ArrayList(); for (int i=0; i< data.length; i++) {...
\\ this is the code i need help to get this part working the
rest works but this and im not sure what is missing or how to make
it work. this is what they asking for to do and there is two errors
the ones shown in the pictures this is all the information I have
from zybooks\\
Q3. (54 Points) Complete a public class to represent a
Movie as described below.
(a-e 4 pts each) (f-h 8 pts...
(JAVA) Given an array of unique positive integers, write a function findSums that takes the array input and: 1. Creates a hashtable called “hashT” and inserts all the elements of the input array in the hashtable. 2. Finds pairs of elements in the hashtable whose sum is another element (sum) in the hashtable and print the pairs in the console. 3. Returns another hashtable names “sums” of those sum elements. For example: Input: [1,5,4,6,7,9] Output: [6,5,7,9] Explanation: 6 = 1...
JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in a given array. If there are no odd numbers in the array, the method should return 0. If the array is empty, the method should also return 0. For example: Test Result System.out.println(countOdd(new int[]{2, 3, 5, 6})); 2 System.out.println(countOdd(new int[]{2})); 0 System.out.println(countOdd(new int[]{})); 0 System.out.println(countOdd(new int[]{-7, 2, 3, 8, 6, 6, 75, 38, 3, 2})); 4 public static int ----------------------------------------------------------------------------------------------------------- 2. Write a static...
JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...
Hey, I was wondering if there’s another way to make these methods not reliable to imports such as “import java.util.Arrays” and “import java.util.Hash” I am still new in coding and would like to know if there’s another way to do it! Here is the code! (Thank you in advance and I will really appreciate it :) ) /** This exercise involves implementing several methods. Stubs for each method with documentation are given here. It is your task to fill out...
Below is my code and the instructions for the code. I can't figure out what's wrong. Please help. Tasks This lab has two parts: Writing a searching function for 1D arrays. Writing a simple class. Part 1 – Searching Continuing with arrays, we will now expect you to find information in an array and derive useful properties from the information stored in an array. Start Eclipse. Change the workspace directory location to something "safe". You may want to temporarily choose...
1) Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second argument is a String. The method should print out a list of the values in the array, each separated by the value of the second argument. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; printArray(myArray, ", ") will print out 1, 22, 333, 400, 5005, 9 printArray(myArray,...