System.out.println nie działa

0

Hej, pewnie problem wynika z czegoś banalnego, ale walczę z tym na różne sposoby i nic. W skrócie - System.out.println nie pokazuje wyniku. Dlaczego tak się dzieje? Będę wdzięczny za pomoc.

"package com.company;

public class Main {
public static void main(String[] args) {

}
public int diceRoll() {
    double randomNumber = Math.random();
    randomNumber = randomNumber * 6;
    randomNumber = randomNumber +1;
    int rand = (int) randomNumber;

System.out.println(rand);
return rand;
}

}"

0

Usuń System.out.println(rand); z funkcji, a w main daj: System.out.println(diceRoll());; musisz jakoś tę funkcję wywołać :)

0

@lion137: pokazuje mi się komunikat "java: <identifier> expected"

0

package com.company;

public class Main {
public static void main(String[] args) {
}
public int diceRoll() {
double randomNumber = Math.random();
randomNumber = randomNumber * 6;
randomNumber = randomNumber +1;
int rand = (int) randomNumber;
return rand;
}
System.out.println(diceRoll());
}

0
package com.company;

public class Main {

    public int diceRoll() {
        double randomNumber = Math.random();
        randomNumber = randomNumber * 6;
        randomNumber = randomNumber +1;
        int rand = (int) randomNumber;
        return rand;
    }

    public static void main(String[] args) {
        System.out.println(diceRoll());
    }


}

0

@lion137: przekopiowałem, teraz wyskakuje mi : "java: non-static method diceRoll() cannot be referenced from a static context"

1 użytkowników online, w tym zalogowanych: 0, gości: 1