Please help (Java)

Hi Everyone,

Please assist with the below question

  1. Write a Java program to:
    1.1 Store three numbers into variables num1, num2 and num3 and then display those numbers in a dialog box.
    1.2 When the OK button of the dialog is pressed, the program should swap the values in the three variables, such that num1 holds the value which was in num2, num2 holds the value which was in num3, and num3 holds the value which was in num1. Hint: used a fourth variable called temp to temporarily store numbers during the swop.

This is what I have done so far, just need help with the fourth variable.

This is what I have done so far.

*import javax.swing.JOptionPane;*

*public class NumberSwop*

*{*
*      public static void main(String [] args)*
*         *
*         {*
*         int num1;*
*         int num2;*
*         int num3;*
*         int temp;*
*          *
*         *
*         num1 = 10;*
*         num2 = 80;*
*         num3 = 15;*
*         *
*         String numString1; *
*         String numString2;*
*         String numString3;*
*                  *
*         JOptionPane.showMessageDialog(null, "10");*
*         JOptionPane.showMessageDialog(null, "80");*
*         JOptionPane.showMessageDialog(null, "15");*
*      *
*         System.exit(0);*
*         }*
*}*
import javax.swing.JOptionPane;

public class NumberSwap {
    public static void main(String[] args) {
        int num1;
        int num2;
        int num3;
        int temp;

        num1 = 10;
        num2 = 80;
        num3 = 15;

        JOptionPane.showMessageDialog(
            null,
            "Number 1: " + num1 +
            "\nNumber 2: " + num2 +
            "\nNumber 3: " + num3);

        temp = num1;
        num1 = num2;
        num2 = num3;
        num3 = temp;

        JOptionPane.showMessageDialog(
            null,
            "Number 1: " + num1 +
            "\nNumber 2: " + num2 +
            "\nNumber 3: " + num3);

        System.exit(0);
    }
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

Please go back over your post to format your code properly

Hi EricNC,

Thanks for the assist I really appreciate it.

Regards,

Hi Sky020,

The above has been noted.