Question

code a calling and called method that reverse their actual and formal parameter names.///java

code a calling and called method that reverse their actual and formal parameter names.///java

Homework Answers

Answer #1
public class ReverseNames {

    public static void reverse(String[] arr) {
        String temp;
        for (int i = 0; i < arr.length / 2; i++) {
            temp = arr[i];
            arr[i] = arr[arr.length - i - 1];
            arr[arr.length - i - 1] = temp;
        }
    }

    public static void print(String[] arr) {
        for (int i = 0; i < arr.length; ++i) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        String[] names = {"ronaldo", "messi", "bale", "hazard"};
        System.out.print("Original array: ");
        print(names);
        reverse(names);
        System.out.print("Reversed array: ");
        print(names);
    }
}

Know the answer?
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
Similar Questions
Code a calling and called a method that demonstrates that actual parameters, that are variables of...
Code a calling and called a method that demonstrates that actual parameters, that are variables of value types, do not have side effects but those of reference types can have such effects. Include appropriate display instructions to prove the point. Use a parameter that is an array of int as your reference type and an element of this array as your value type. Use java and explain the code, thanks
java 1) Create a mutator method called setPosition that accepts one integer parameter. Update the position...
java 1) Create a mutator method called setPosition that accepts one integer parameter. Update the position variable by adding the position to the parameter variable. 2)debug the code public class food { public static void main(String[] args) { Fruits apple = new Fruits(20); // Write the statement to call the method that will increase the instance variable position by 6. Fruits.setPosition(6); apple.getPosition(); } }
• First, create a function called addNumber, which has a formal parameter for an array of...
• First, create a function called addNumber, which has a formal parameter for an array of integers and increase the value of each array element by a random integer number between 1 to 10. o Add any other formal parameters that are needed. • Second, create another function called printReverse that prints this array in reverse order. • Then, you need to write a C++ program to test the use of these two functions.
Write Java code that attempts to call a method named bootUp() which takes a String parameter...
Write Java code that attempts to call a method named bootUp() which takes a String parameter and returns an integer value. The String parameter should be read from a file named "bootConfig.txt" and is the only value in the file. If a BootUpException is thrown, print the Exception object's message. If a DriverException occurs, call the reboot() method and rethrow the original DriverException object. If any other type of Exception is thrown, print a generic error message to the console....
Using Java code and ARRAYS, please write a program that takes in the names of four...
Using Java code and ARRAYS, please write a program that takes in the names of four individuals and prints out all the names. The number of names (4) is predetermined.
How do you code in Java a method (lets say its called PosOddAverage) that: - Takes...
How do you code in Java a method (lets say its called PosOddAverage) that: - Takes an array of doubles as input - Prints the avearge of positive odd numbers in the array - Prints 'ERROR' for empty input array An Example: Input: [1.2,1.5,0.0,-2.3,3.5,7.1,-1.3] Output: 4.03333333 Thanks :)
Code in Java Create a file called Factorial.java. This file should have the following method: public...
Code in Java Create a file called Factorial.java. This file should have the following method: public static long calculate(long n) Factorial.calculate should recursively calculate n!, where 0! = 1 and n! = n(n−1)!. The method should also print out an error and exit if n < 0 or n > 20, since factorial is not defined for negative numbers and will overflow Java’s long variable with larger numbers (if we used an int, it would overflow even sooner!). Inside Factorial.java,...
Write a Java part code to do the following   : ** Suppose a file called infile stored...
Write a Java part code to do the following   : ** Suppose a file called infile stored in drive D: ,filled with five integers(1000,200,3030,40 and 500) Read  the integers from infile then store them in array called ar[] and print it elements. Method called search( ) to print the location of   value 500. Method called sort() to sort array elements. Build another file called outfile in drive D: to save the sorted array elements . Note : Use ArrayIndexOutOfBoundsException when you use array...
-Previously - java class with one static method. In the static method called beforeThis. take 2...
-Previously - java class with one static method. In the static method called beforeThis. take 2 strings as inputs and return a string. Code for the method should look for 1st input String within the 2nd input, and return everything from 2nd input string that comes before. ex: 1st input : "tennis" 2nd input : "A tabletennis is in the basement" method returns: "A table"
Write the following method in java: public static void reverse(Queue<Integer> q) which uses a stack to...
Write the following method in java: public static void reverse(Queue<Integer> q) which uses a stack to reverse the order of all the items in q.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT