Question

What I need: Create a new program named Reverse4 and declare four integer variables with the...

What I need:

Create a new program named Reverse4 and declare four integer variables with the values 23, 45, 55, and 67.

Add a method named Reverse that reverses the positions of four integer variables. The Reverse method should accept the variables as references.

Write a Main() method that displays the four variables both before and after reversing them to ensure the method works correctly.

What I have:

using System;
class Reverse4 {

public static void reverse(ref int num1, ref int num2, ref int num3, ref int num4)
{
int temp;

temp = num1;
num1 = num4;
num4 = temp;

temp = num2;
num2 = num3;
num3 = temp;
}

public static void Main (string[] args) {
int a = 23;
int b = 45;
int c = 55;
int d = 67;

Console.WriteLine("Before swap");
Console.WriteLine(a + ", " + b + ", " + c + ", " + d);

/* calling a function to swap the values */
reverse(ref a, ref b, ref c, ref d);

Console.WriteLine("After swap");
Console.WriteLine(a + ", " + b + ", " + c + ", " + d);
}
}

Error I get:

Compilation failed: 1 error(s), 0 warnings

NtTest444c819b.cs(13,16): error CS0117: `Reverse4' does not contain a definition for `Reverse'
Reverse4.cs(2,7): (Location of the symbol related to previous error)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Declare the class Reverse4 as public and its working fine

using System;
public class Reverse4 {

public static void reverse(ref int num1, ref int num2, ref int num3, ref int num4)
{
int temp;

temp = num1;
num1 = num4;
num4 = temp;

temp = num2;
num2 = num3;
num3 = temp;
}

public static void Main (string[] args) {
int a = 23;
int b = 45;
int c = 55;
int d = 67;

Console.WriteLine("Before swap");
Console.WriteLine(a + ", " + b + ", " + c + ", " + d);

/* calling a function to swap the values */
reverse(ref a, ref b, ref c, ref d);

Console.WriteLine("After swap");
Console.WriteLine(a + ", " + b + ", " + c + ", " + d);
}
}

Add a comment
Know the answer?
Add Answer to:
What I need: Create a new program named Reverse4 and declare four integer variables with the...
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
  • java question, my questions are in the following codes with comments, just answer next or under...

    java question, my questions are in the following codes with comments, just answer next or under it thanks! theres only few, so no worry. import java.security.SecureRandom; public class clsTestRand {    public static void main(String[] args) {        // TODO Auto-generated method stub        //int num1, num2, num3, num4, num5, num6;        int num1 = 0;        int num2 = 0;        int num3 = 0;        int num4 = 0;        int...

  • Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values...

    Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...

  • i need help fixing my code. here is the assignment: Make a class that contains the...

    i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...

  • What I need: Write a program named Averages that includes a method named Average that accepts...

    What I need: Write a program named Averages that includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average. For example, if 7 and 4 were passed to the method, the ouput would be: 7 4 -- Average is 5.5 Test your function in your Main(). Tests will be run against Average() to determine that it works correctly when passed one, two, or three numbers, or an array of numbers. What I...

  • Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...

    Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...

  • I do not understand why the swap methods are not doing anything for the variable x...

    I do not understand why the swap methods are not doing anything for the variable x and y in the main method. When are variables affected by the other methods and when they do not get modified by the other methods? (The answer is A). Thank you so much in advance, 24. What does the following code print? public class Swapper [ public static void main (String[] args) I int [ ] x = int [ ] y = {4,5,6,7,8};...

  • QUESTION 3 (20) Create a constructor class Sum that has public integer variables num1 and num2....

    QUESTION 3 (20) Create a constructor class Sum that has public integer variables num1 and num2. Include a default constructor and a method Add that accepts the two integer parameters, calculates and outputs the sum. In your main class Calculate include a main method that prompts the user to enter 2 integer values and create a reference called total for the constructor Sum. Output the values entered by the user and the sum of the values in the command line...

  • // 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and...

    // 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and //1 usability error. Identify them all. import java.util.scanner; //This program finds the average of three input values. public class Arithmeticx { public static void main( String [] args ) // declare variables double number1, number2, number3; // input data scanner in = newscanner( ); System.out.print( "Number 1? " ); System.out.print( "Number 2? " ); System.out.print( "Number 3? " ); number 1 = in.nextDouble; number...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • For the following C# program: Let’s add one more user defined method to the program. This...

    For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...

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