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

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

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

by Guest » 07 Jan 2025, 06:24

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.

Top