1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
matrenka [14]
3 years ago
3

Write a public static method named print Array, that takes two arguments. The first argument is an Array of int and the second a

rgument 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, " - ") will print out 1 - 22 - 333 - 400 - 5005 - 9
Computers and Technology
1 answer:
podryga [215]3 years ago
3 0

Answer:

Here is the output.

Explanation:

import java.util.Arrays;  

public class Main{  

   public static void main(String[] args){        

       int[] array={43,42,23,42,4,56,36,7,8,676,54};

       System.out.println(Arrays.toString(array));

       printArray(array,"*");

       System.out.println(""+getFirst(array));

       System.out.println(""+getLast(array));

       System.out.println(Arrays.toString(getAllButFirst(array)));

       System.out.println(""+getIndexOfMin(array));

       System.out.println(""+getIndexOfMax(array));

       System.out.println(Arrays.toString(swapByIndex(array, 1,2)));

       System.out.println(Arrays.toString(removeAtIndex(array,3)));

       System.out.println(Arrays.toString(insertAtIndex(array,3,65)));

   }  

   //---1----

   public static void printArray(int[] arr, String sep){  

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

           System.out.print(" "+arr[i]+" "+sep);  

       }  

       System.out.println(" "+arr[arr.length-1]);  

   }  

   //---2----  

   public static int getFirst(int[] arr){  

       return arr[0];  

   }

   //---3----  

   public static int getLast(int[] arr){  

       return arr[arr.length-1];  

   }  

   //---4-----  

   public static int[] getAllButFirst(int[] arr){  

       int[] anotherArray=new int[arr.length-1];  

       for(int i=1; i<arr.length;i++){  

           anotherArray[i-1]=arr[i];  

       }

       return anotherArray;

   }

//---5------  

   public static int getIndexOfMin(int[] arr){  

       int index=0;  

       int min=arr[0];  

       for(int i=1; i<arr.length;i++){  

           if(min>arr[i]){  

               min=arr[i];  

               index=i;  

           }  

       }

       return index;  

   }  

   //---6------  

   public static int getIndexOfMax(int[] arr){  

       int index=0;  

       int max=arr[0];  

       for(int i=1; i<arr.length;i++){  

           if(max<arr[i]){  

               max=arr[i];  

               index=i;  

           }  

       }  

       return index;  

   }  

   //---7------  

   public static int[] swapByIndex(int[] arr, int a , int b){  

       int temp=arr[a];  

       arr[a]=arr[b];  

       arr[b]=temp;  

       return arr;  

   }  

   //---8------  

   public static int[] removeAtIndex(int[] arr, int index){  

       int[] anotherArray = new int[arr.length - 1];  

for (int i = 0, k = 0; i < arr.length; i++) {  

if (i == index) {  

continue;  

}  

anotherArray[k++] = arr[i];  

}  

// return the resultant array  

return anotherArray;  

   }  

//---9------  

   public static int[] insertAtIndex(int[] arr, int index, int element){  

       int[] anotherArray = new int[arr.length + 1];  

for (int i = 0, k=0;k < arr.length+1; k++) {  

if (k == index) {  

anotherArray[k]=element;  

               continue;  

}  

anotherArray[k] = arr[i++];  

}  

// return the resultant array  

return anotherArray;  

   }  

//---10------  

   public static boolean isSorted(int[] arr){  

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

           if (arr[i+1]<arr[i]){  

               return false;  

           }  

       }  

       return true;  

   }  

}

You might be interested in
What sort of technique would you use to sort 10,000 items using just 1000 available slot in your RAM?
beks73 [17]

Answer:

d. Merge sort

Explanation:

Merge sort is example of an efficient sorting alogrithm. The Divide and conquer rule is used in this technique. This method breakdown the list into multiple sublists and each sublist contains a single element. This technique merged in the form of sorted lists. This technique uses external memory of the system while sorting.

Merge sort is used to sort the 10,000 items using only 1,000 slots available in the RAM.

5 0
3 years ago
Your company wants to use an IoT device but wants to make sure it does not interfere with other RF devices that use the 2.4 GHz
jonny [76]

Answer:

C. Z-wave

Explanation:

The Z wave is a wireless communications protocol used primarily for automation. The Z- wave operates using a mesh network and then uses low energy radio waves to communicate from appliance to appliance.

The Z wave operates on a lower frequency than most other popular RF devices, thus making interference nonexistent.

The range of the Z-wave is 100m. Hence, it can give a perfect coverage from the base station to the company.

<em>Option A is wrong</em> . This is because the Zigbee is insecure and has a low coverage range (10m-20m). This means that there are possibilities of interference and also improper coverage beyond 50 m.

<em>Option B is wrong.</em> This is because Bluetooth devices are insecure, can loose connections under certain conditions. They have a range of 10m which is a lot lower than 50m benchmark.

<em>Option D is wrong</em>. NFC stands for Near Field Communication. This means its range is practically about 4cm and it cannot be used for long ranges as the company intends.

6 0
4 years ago
How do spear phishing attacks differ from standard phishing attacks?
mina [271]

Answer:

Phishing attacks normally target random people on mass amount by sending emails to users. In the other hand the spear phishing only targets 1 person hence the name "spear".

Hope this help please give the brainliest award.

5 0
3 years ago
For this activity, you will practice being both proactive and reactive to bugs. Both are necessary to get rid of errors in code.
Illusion [34]

Answer:

okk

Explanation:

4 0
3 years ago
9,105,?,161,?,241,257,?,401​
almond37 [142]
What is the question……..
4 0
3 years ago
Read 2 more answers
Other questions:
  • How do you change colors for presentation to blue warm in power point?
    11·1 answer
  • What would be a standard way for anyone outside an agile team( for example, delivery partner partner of the account, head of the
    14·1 answer
  • Which phrase refers to the collection of geospatial data through the use of satellite images/pictures?
    13·1 answer
  • You want to verify whether a PTR record exists for the Serv2.csmpub.local host, but you don't know the IP address. Which of the
    8·1 answer
  • Which one is not considered part of the cinematography team?
    7·2 answers
  • Name the type of software which provides the user interface. [1 mark
    5·1 answer
  • Robin has four copies of her midterm paper saved to a single folder on her
    9·1 answer
  • Information about www
    14·1 answer
  • What are the methods used in research methodology?
    12·1 answer
  • explain how principles of computational thinking skills are applied in finding solutions that can be interpreted into software a
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!