I want to make a small program to get the desired result by adding two random numbers. For example our desired number is 30 then random no 1 and no 2 should be 15-15, 13-17, 10-20 or anything else. I made this program which shows the sum of random numbers but not desired sum.
import java.util.*;
import java.util.Random;
public class Problem {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
Random rand= new Random();
Random random= new Random();
int r= rand.nextInt(100)+1;
int r1= random.nextInt(100)+1;
int sum= r+r1;
System.out.println(r +" + "+r1+ " sum is: " + sum);
}
}
Aucun commentaire:
Enregistrer un commentaire