Hi i am new to java, and am learning how to pass values through methods.
i have this program which does not seem to pass the values correctly?
Plz note im not allowed to use return values for this program.
the modulus doesnt always give the correct answer. E.g. 1 % 2 = 5 but the program gives 1? E.g. 11 % 5 = 2, but program gives 1?
i think because the values are not being passed properly. But again im sorta new to doing thing in java so not sure.
Anyone noe what im doing wrong and how to fix it?
i have this program which does not seem to pass the values correctly?
Plz note im not allowed to use return values for this program.
Code:
class prac7assignment
{
public static void main(String[] args) {
int modulusValue;
System.out.println("Welcome to the Modulus calculator");
getdata();
return;
}
public static void getdata() {
int number1, number2;
System.out.println("Please enter your first number:");
number1 = Keybd.in.readInt();
System.out.println("Please enter your second number:");
number2 = Keybd.in.readInt();
calculate_modulus(number1, number2);
return;
}
public static void calculate_modulus(int number1, int number2) {
int modulusValue;
modulusValue = number1 % number2;
displayModulus (modulusValue);
return;
}
public static void displayModulus (int modulusValue) {
System.out.println("The modulus value is: " + modulusValue);
return;
}
}
i think because the values are not being passed properly. But again im sorta new to doing thing in java so not sure.
Anyone noe what im doing wrong and how to fix it?
Comment