帶著疑問看故事

茆伟昊發表於2024-09-27

package mwh;

import java.util.Random;

public class Problem {
public static void main(String[] args) {
Problem manner=new Problem();
for(int i=1;i<=30;i++){
manner.problem();
}

    }

    void problem(){
        Random r1=new Random();
        int num1= r1.nextInt(9)+1;
        Random r2=new Random();
        int num2=r2.nextInt(9)+1;
        String[] operators = {"+", "-", "*", "/"};
        int randomIndex = (int)(Math.random() * operators.length);
        String randomOperator = operators[randomIndex];
        System.out.println(num1+randomOperator+num2+"=");
    }

}

相關文章