Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a void method that accepts 2 ints as arguments -one is low number and one

ID: 3607038 • Letter: W

Question

write a void method that accepts 2 ints as arguments -one is low number and one is high. your method first determines that the arguments are in the correct order and swaps them if they are not(print a message letting the user know this has occurred).

import java.util.Scanner;

public class question3{

public static void main(String[] args){

int first = 0;

int second = 0;

Scanner in = new Scanner(System.in);

System.out.println(" Enter two numbers");

first = in.nextInt();

second = in.nextInt();

}

public static void order(int first, int second){

if(first < second){

System.out.println(" the numbers " + first + " and " + second + " are in correct order");

System.exit(0);

}

else{

int temp;

temp = first;

first = second;

second = temp;

System.out.println(" The numbers were not in ascending order and hence have been swapped ");

System.out.println(" first" + first + "second " + second);

System.exit(0);

}

}

}

doesn't work

Explanation / Answer

Hi.... i have changed little bit code that you have provided. Please check below code that i have changed.

Question3.java

import java.util.Scanner;
public class Question3{
public static void main(String[] args){
int first = 0;
int second = 0;
Scanner in = new Scanner(System.in);
System.out.println(" Enter two numbers");
first = in.nextInt();
second = in.nextInt();
order(first,second);
}
public static void order(int first, int second){
if(first < second){
System.out.println(" the numbers " + first + " and " + second + " are in correct order");
System.exit(0);
}
else{
int temp;
temp = first;
first = second;
second = temp;
System.out.println(" The numbers were not in ascending order and hence have been swapped ");
System.out.println(" first" + first + "second " + second);
System.exit(0);
}
}
}

Output:

Enter two numbers
-1
-4
The numbers were not in ascending order and hence have been swapped
first-4second -1

Another output:

Enter two numbers
-2
5
the numbers -2 and 5 are in correct order

Whatever changes made bye me i just made it in bold. Please check once and let me know any issues.

Thanks a lot. All the best.