So I would like to multiply a first digit by 2. I have to randomize either 51-55 but multiply that very first digit by 2 whichever the number may come out to be. I also need to keep the string.
FOR EXMAPLE:
Code generates 51, multiply 5 * 2 to get 10 1
or if it generates 54, multiply 5 * 2 to get 10 4
the 1 and the 4 always stay the same, only the 5 is getting multiplied
I need this to be in JAVA but so far
Here is my code:
import java.util.Random;
public class Randoms {
public static void main(String[] args) {
Random rng = new Random();
String x;
int max = 55;
int min = 51;
int rand_int1 = rng.nextInt((max - min) + 1) + min;
// 51-55
x = Integer.toString(rand_int1);
import java.util.Random; public class Randoms { public static void main(String[] args) { Random rng = new Random(); String x; int max = 55; int min = 51; int rand_int1 = rng.nextInt((max - min) + 1) + min; // 51-55 x = Integer.toString(rand_int1); rand_int1 = 10 * (2 * rand_int1 / 10) + (rand_int1 % 10); // doubles the first digit System.out.println(rand_int1); } }
Get Answers For Free
Most questions answered within 1 hours.