This is the starting point for the Java code... public class NumberWork { public
ID: 3631001 • Letter: T
Question
This is the starting point for the Java code...public class NumberWork {
public static void main(String[] args) {
conNumbers(9, 3, 2);
conNumbers(1, 2, 3);
conNumbers(5, 4, 3);
conNumbers(-2, 0, -1);
conNumbers(-1, 10, 5);
}
public static void conNumbers(String a, String b, String c){
Starting under the method conNumbers, write a method that accepts the three numbers given in the test cases and returns whether they are consecutive or not. The order doesn't matter, so long as the numbers if taken out of the code could be arranged in a consecutive order. The method should return with true or false answers to whether each test contains consecutive numbers, for example the output for these tests should look like this...
false
true
true
true
false
Also you must start and work within the same method header
public static void conNumbers(String a, String b, String c){
Good Luck and Thanks in advance....
Explanation / Answer
Ok, this is something like what you are looking for. It will sort the numbers so it doesn't matter what order they are entered in, then checks if they are consecutive. If they are it prints true, otherwise false. If you need it to return a value and print outside the method just change the prints to returns. Hope it helps. public class NumberWork { public static void main(String[] args) { conNumbers(9, 3, 2); conNumbers(1, 2, 3); conNumbers(5, 4, 3); conNumbers(-2, 0, -1); conNumbers(-1, 10, 5); } public static void conNumbers(String a, String b, String c){ int int two = Integer.parseInt(b); int three = Integer.parseInt(c); if (one three) { int first = one; int second = three; int third = two; } else if (two two) { int first = two; int second = one; int third = three; } else if (two three) { int first = two; int second = three; int third = one; } else if (three three) { int first = three; int second = two; int third = one; } else if (three three) { int first = three; int second = one; int third = two; } else { int first = one; int second = two; int third = three; } if ((one +1) == two && (two+1) == three) { print("true"); } else { print("false"); } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.