I have been struggling with this because I dont\' understand how to return an ar
ID: 3528796 • Letter: I
Question
I have been struggling with this because I dont' understand how to return an array. it keeps telling me cannot convert from int[] to int but I defined myList[] as an array and that is what im trying to return. here is my code. import java.util.Scanner; public class Lab6_15Montgomery { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //Create scanner Scanner input = new Scanner(System.in); //prompt user to enter numbers System.out.println("Enter ten numbers "); //set length to 10 int LENGTH = 10; //create array int []list = new int [LENGTH]; //transfer inputs into array for (int i = 0; i < LENGTH; i++){ list[i] = input.nextInt(); //print array System.out.println("The elements are " + list[i]); //invoke method eliminateDuplicates(list); //display results System.out.println("The distinct numbers are: " + eliminateDuplicates(list)); } } public static int eliminateDuplicates(int[] list){ //create variable "count" to set the length of new array int count = 0;; //create new array for duplicate values int newList[] = new int [count]; for (int i = 0; i < list.length; i++){ for (int j = 0; j < list.length; j++){ if ((list[i] == list[j]) && (i != j)){ count ++; int temp = newList[i]; newList[i] = newList[j]; newList[j] = temp; } //return temp; } } return newList; }Explanation / Answer
public static void removeDuplicates(char[] str) { if (str == null) return; int len = str.length; if (len < 2) return; int tail = 1; for (int i = 1; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.