Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given two int variables j and k , an int array zipcodeList that has been

ID: 3568428 • Letter: Y

Question

You are given two int variables j and k , an int array zipcodeList that has been declared and initialized by taking the inputs, and a boolean variable duplicates.


Write some code that assigns true to duplicates if any two elements in the array have the same value, and that assigns false to duplicates otherwise.
Use only j,k,zipcodeList and duplicates

----------------------------------------------------

import java.util.Scanner;
class FindDuplicate{

   public static void main(String arg[]){
   boolean duplicates=false;
       int j,k;
       int[] zipcodeList=new int[5];
           Scanner scanner =new Scanner(System.in);
           System.out.println("Filling the array:");
               for(int i=0;i<5;i++){
                       System.out.println("Enter zipcodeList["+i+"]:");
                       zipcodeList[i]=scanner.nextInt();

               }

               ///{
               //write your code here
               //start
  

               //end
        ///}
                 

       System.out.println("value of the duplicates:"+duplicates);         
       }

}

++++++++++++++++++++++++++++++++++++++++++++++++++++++

Complete the following empty recursive void method, reverse, that accepts an integer array, a starting index and an ending index, and reverses the array.
Reversing an array involves:
Nothing if the array has 0 or 1 elements.
swapping the first and last elements of the array and then reversing the remainder
of the array (2nd through next-to-last elements).

------------------------------------------------------------

import java.util.Scanner;
class arrayreverse{




static void reverse(int[] arr,int start,int end){
   ///{
   //write your code here
   //start


while (start<=end)
{
int temp = arr[start];
arr[start]= arr[end];
arr[end]= temp;

start++;
end--;
  
}
System.out.println("array after reverse is:");
for(int i=0;i System.out.print(arr[i]+" ");


   //end
   ///}


}

public static void main(String arg[]){

Scanner scanner=new Scanner(System.in);
System.out.println("Enter the size of an array:");
int size=scanner.nextInt();
int[] a=new int[size];
for(int i=0;i System.out.print("Enter a["+i+"]:");
a[i]=scanner.nextInt();
}
System.out.println("Enter start index(1 to "+size+"):");
int start_index=scanner.nextInt();
System.out.println("Enter the end index(1 to "+size+"):");
int end_index=scanner.nextInt();

reverse(a,start_index-1,end_index-1);
}
}

Explanation / Answer

Answer to isReverse()....

-----------------------------------------------

import java.util.Scanner;
class ReverseTest{

public static boolean isReverse(int[] s1,int[] s2){

int len_array = s1.length;

for(int i = 0, j = len_array - 1; i < len_array; i++, j--){

   if( s1[i] != s2[j] )

   return false;

   }

   return true;

   }

public static void main(String arg[]){
Scanner scanner =new Scanner(System.in);
int[] a=new int[3];
int[] b=new int[3];
System.out.println("Filling the 2nd array:");
for(int i=0;i<3;i++){
System.out.println("Enter a["+i+"]:");
a[i]=scanner.nextInt();
}
System.out.println("Filling the 2nd array:");
for(int j=0;j<3;j++){
System.out.println("Enter b["+j+"]:");
b[j]=scanner.nextInt();
}

System.out.println("reverese:"+isReverse(a,b));

}

}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Answer to Duplicates

------------------------------------------------------------------------------------------------------------------

import java.util.Scanner;
class FindDuplicate{

public static void main(String arg[]){
boolean duplicates=false;
int i, j,k;
int[] zipcodeList=new int[5];
Scanner scanner =new Scanner(System.in);
System.out.println("Filling the array:");
for(i=0;i<5;i++){
System.out.println("Enter zipcodeList["+i+"]:");
zipcodeList[i]=scanner.nextInt();

}

           {

           for(i = 0; i < zipcodeList.length - 1; i++){

           for(j = i; j < zipcodeList.length; j++){

           if( zipcodeList[i] == zipcodeList[j] )

           duplicates = true;

           }

           }
           }


System.out.println("value of the duplicates:"+duplicates);   
}

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Answer to recursive reversing of an array....

----------------------------------------------------------------------------------------------------------------

import java.util.Scanner;
class arrayreverse{

static void reverse(int[] arr,int start,int end){

if( end-start > 1 ){
int temp = arr[end];
arr[end] = start;
arr[start] = temp;
  
reverse(arr, start+1, end-1);
}

}

public static void main(String arg[]){

Scanner scanner=new Scanner(System.in);
System.out.println("Enter the size of an array:");
int size=scanner.nextInt();
int[] a=new int[size];
for(int i=0;i<size;i++){
System.out.print("Enter a["+i+"]:");
a[i]=scanner.nextInt();
}
System.out.println("Enter start index(1 to "+size+"):");
int start_index=scanner.nextInt();
System.out.println("Enter the end index(1 to "+size+"):");
int end_index=scanner.nextInt();

reverse(a,start_index-1,end_index-1);
}

System.out.println("array after reverse is:");
for(int i=0;i<a.length;i++)
   System.out.print(a[i]+" ");
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote