Код: Выделить всё
// class definition - to simulate and create a Dice class and execute its methods
class Dice
{
// properties
int dotCount = 1; // initializing the dice to show side with 1 dot for testing
// show the number of dots that the dice is showing
void showDots(){
System.out.println("Number of dots: " + dotCount);
}
// simulate rolling of dice
void rollDice(){
dotCount = 5; // value assigned to simulate roll dice. TODO Use Random later
System.out.println("Dice Rolled");
}
public static void main (){
Dice obj = new Dice();
obj.showDots();
obj.rollDice();
obj.showDots();
}
}
Код: Выделить всё
Dice.main();Количество точек: 1
Бросание кубиков
Количество точек: 5
Однако, когда я заменяю строку:
Код: Выделить всё
public static void main ()Код: Выделить всё
public static void main (String args[])| Dice.main();
невозможно найти символ
символ: переменная Dice
Какой аргумент мне нужно предоставить в Dice.main() , чтобы он работал во втором случае? Я попробовал Dice.main({""}), не помогло.
Подробнее здесь: https://stackoverflow.com/questions/791 ... java-which
Мобильная версия