So I would like to multiply a first digit by 2. I have to randomize either 51-55 but multiply that first digit by 2 whichever the number may come out to be. I also need to keep the string.
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);
// from here whatever the number may be either 51-55, I ONLY want to double the first digit by 2.
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 += (rand_int1 % 10); // this add the last digit to rand_int1 // for example if number is 54, then it adds 4. so, number will be 58. first digit is multiplied by 2. System.out.println(rand_int1); } }
Get Answers For Free
Most questions answered within 1 hours.