'How do I execute this java program in eclipse? (Beginner to coding, not understanding a lot of this, professor being vague)
So basically I followed the problem listed on the assignment, and I put the following text into my console:
public class mystery {
public static int mystery(int x, int y) {
while (x != 0 && y != 0) {
if (x < y) {
y -= x;
} else {
x -= y;
}
}
return x + y;
}
public static void main(mystery args[]) {
}
}
It's asking me to write the main method for the program, put in the following values [mystery(3,3), mystery(5,3), mystery(2,6)], and indicate the value returned but I'm not quite sure on how to go about this and my professor was being very vague.
Solution 1:[1]
public static void main(String[] args) {
System.out.println(mystery(3,3));
}
public static int mystery(int x, int y) {
while (x != 0 && y != 0) {
if (x < y) {
y -= x;
}
else {
x -= y;
}
}
return x + y;
}
So you created a method in public static int mystery, but you never called it in your main method (Main is the part of the code that actually runs). Also for future note "I put the following text into my console" the console is the part at the bottom of the IDE, or the part where your outputs are shown, just so you dont get more confused down the line, hope this helps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fugazzie |
