私は Java でメソッドを教えていますが、ユーザー入力に基づいてブール値の true/false を出力しない理由がわかりません。どんな助けでも素晴らしいでしょう。特にメソッドの名前付けと、void/private などが必要な場合に混乱します。ありがとう!
import java.util.Scanner;
public class javaPractice
{
public static void main (String[]args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int x = input.nextInt();
methods calling = new methods(x);
calling.oddTest();
calling.returnBoolean();
}
}
public class methods
{
private int userInput;
private boolean output;
public methods (int num) //constructor
{
userInput = num;
}
public void oddTest ()
{
if (userInput % 2 == 0)
{
output = true;
}
else if (userInput % 2 != 0)
{
output = false;
}
}
public boolean returnBoolean ()
{
return output;
}
}