Question

Problem: Zipper For this problem, you have some starter code. Save it and run it a few times -- you will see that it generate

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;
public class Main
{
   public static void main(String[] args)
   {
   Random random = new Random();
int size=random.nextInt(10) ;
int a1[]=new int[size];
int a2[]=new int[size];
for(int i=0;i<size;i++)
a1[i]=random.nextInt(10);
for(int i=0;i<size;i++)
a2[i]=random.nextInt(10);
System.out.print("arr1 is [");
printArray(a1);
System.out.print("]");
System.out.print("\narr2 is [");
printArray(a2);
System.out.print("]");
System.out.print("\narr3 is [");
zip(a1,a2);
System.out.print("]");
   }
   static void printArray(int a[])
   {
   for(int i=0;i<a.length;i++)
   System.out.print(a[i] + " ");
   }
   static void zip(int a1[],int a2[])
   {
   int a3[]=new int[2*a1.length];
   for(int j=0,i=0;i<a1.length;i++)
   {
   a3[j++]=a1[i];
   a3[j++]=a2[i];
   }
   //print a3
   printArray(a3);
   }
}

arrl is [6 1 arr2 is [6 1 arra is [6 6 .Program finished with exit code 0 Press ENTER to exit cons ole.

Main java import java.util. Random; 2 public class Main 3{ public static void main(string []args) 4 5 Random random new Rando

arrl is [4 87 07 3 ] arr2 is [5 8 3 5 2 8 6 1 arra is [4 5 a B 7 3 3 5 0 2 78 3 6 1 --Program finished with exit code 0 Press

Add a comment
Know the answer?
Add Answer to:
Problem: Zipper For this problem, you have some starter code. Save it and run it a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Your goal is to create an ‘Array’ class that is able to hold multiple integer values....

    Your goal is to create an ‘Array’ class that is able to hold multiple integer values. The ‘Array’ class will be given functionality through the use of various overloaded operators You will be given the main() function for your program and must add code in order to achieve the desired result. Do not change any code in main(). If something is not working, you must change your own code, not the code in main(). Assignment 5: overloading member functions. Overview:...

  • CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input...

    CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input to Program: A file containing lines of data, such that each line has 2 integers on it The first integer represents a zip code (in Brooklyn or the Bronx), and the second represents the number of voters in that zip code. Output: All output may be displayed to the screen. In main: 1. Your program will read in all of the data in the...

  • The following code skeleton contains a number of uncompleted methods. With a partner, work to complete...

    The following code skeleton contains a number of uncompleted methods. With a partner, work to complete the method implementations so that the main method runs correctly: /** * DESCRIPTION OF PROGRAM HERE * @author YOUR NAME HERE * @author PARTNER NAME HERE * @version DATE HERE * */ import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class ArrayExercises { /** * Given a random number generator and a length, create a new array of that * length and fill it from...

  • I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good...

    I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr. Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test...

  • please explain this Java problem with source code if possible Project: Strictly identical arrays Problem Deseription:...

    please explain this Java problem with source code if possible Project: Strictly identical arrays Problem Deseription: Two arrays are strictly identical if their correspondimg elements are equal Write a program with class name StrictlyIdentical that prompts the user to enter two lists ed integers of size 5 and displays whether the two are strictly identical. Usc following method header to pass two arrays and retum a Boolcan public static boolean cualsint[] array 1, int[] array2) Method will return true if...

  • I need help modifying this code Problem: Alphabet Monster that gets offended Write a program that...

    I need help modifying this code Problem: Alphabet Monster that gets offended Write a program that simulates a monster which acts happy when fed a letter, and unhappy when fed any other character. As long as the user keeps feeding the monster, the monster keeps asking for more, until it is offered a digit -- at that point the monster is offended and the program ends! Input Validation: • None required. Requirements: • See Alphabet Monster, LAB 6 • Use...

  • For Project 02 you’re going to take starter code I’m providing (See in BlackBoard under Projects->Project...

    For Project 02 you’re going to take starter code I’m providing (See in BlackBoard under Projects->Project 02). The zip file contains a P02.java, a HelperClass.java, and an enumeration under Money.java. The only coding you’ll do will be in P02.java. I’ve already provided you with the menu and switch as well as all the methods you’ll need stubbed out. Your assignment is to take the program and complete it without adding any more methods but merely adding code to those stubbed...

  • starter code To write a program using the starter code which is TestLinkedList to see if...

    starter code To write a program using the starter code which is TestLinkedList to see if the LinkedList program has bugs. It will produce ether a pass or fail.More information is in the first two pictures. LinkedList.java /** * @author someone * * Implements a double-linked list with four errors */ public class LinkedList<E> { // The first and last nodes in the list private Node<E> head, tail; // Number of items stored in the list private int size; //...

  • Using the diagram below and the starter code, write Document Processor that will read a file...

    Using the diagram below and the starter code, write Document Processor that will read a file and let the user determine how many words of a certain length there are and get a count of all of the word lengths in the file. Your program should do the following: The constructor should accept the filename to read (word.txt) and then fill the words ArrayList up with the words from the file. The countWords method should accept an integer that represents...

  • use java and write in text a. Rewrite the following code segment using if statements. Assume...

    use java and write in text a. Rewrite the following code segment using if statements. Assume that grade has been declared as of type char. char grade= 'B';; switch (grade) { case 'A': System.out.println("Excellent"); break case 'B': System.out.println("Good"); default: System.out.println("you can do better”); } - b. write Java code that inputs an integer and prints each of its digit followed by ** e.gif the integer is 1234 then it should print 1**2**3**4 e.g. if the integer is 85 then it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT