Welches Argument muss ich in Notebook in der Hauptmethode in Java angeben, die das Argument „String args[]“ enthält?Java

Java-Forum
Guest
 Welches Argument muss ich in Notebook in der Hauptmethode in Java angeben, die das Argument „String args[]“ enthält?

Post by Guest »

Code: Select all

// 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();
}
}
In Notebook, wenn der folgende Code in der nächsten Zelle ausgeführt wird:

Code: Select all

Dice.main();
Die Ausgabe ist wie erwartet:

Anzahl der Punkte: 1
Gewürfelte Würfel
Anzahl der Punkte: 5

Wenn ich jedoch die Zeile ersetze:

Code: Select all

public static void main ()
mit

Code: Select all

public static void main (String args[])
Ich erhalte die folgende Fehlermeldung:

| Dice.main();
Symbol kann nicht gefunden werden
Symbol: Variable Dice

Welches Argument muss ich in Dice.main() angeben? damit es im zweiten Fall läuft? Ich habe Dice.main({""}) ausprobiert, es hat nicht funktioniert.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post