Question

So I would like to multiply a first digit by 2. I have to randomize either...

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.

Homework Answers

Answer #1
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);
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
So I would like to multiply a first digit by 2. I have to randomize either...
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...
Write a for loop that prints: 1 2 ... userNum Ex: userNum = 4 prints: 1...
Write a for loop that prints: 1 2 ... userNum Ex: userNum = 4 prints: 1 2 3 4 import java.util.Scanner; public class ForLoops { public static void main (String [] args) { int userNum; int i; Scanner input = new Scanner(System.in); userNum = input.nextInt(); for (/* Your code goes here */) { System.out.print(i + " "); } } } Need to fill out the "for" solved in JAVA
The AssemblyLine class has a potential problem. Since the only way you can remove an object...
The AssemblyLine class has a potential problem. Since the only way you can remove an object from the AssemblyLine array is when the insert method returns an object from the last element of the AssemblyLine's encapsulated array, what about those ManufacturedProduct objects that are "left hanging" in the array because they never got to the last element position? How do we get them out? So I need to edit my project. Here is my AssemblyLine class: import java.util.Random; public class...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with...
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Please use my template import java.util.Scanner; public class...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
(Sure, take your time. would you like me to post this again?) Thanks in advance !...
(Sure, take your time. would you like me to post this again?) Thanks in advance ! Write the following methods in java class ARM that represent state information as well as functional blocks of the ARM platform. [Go through the following 5 classes then write methods for the instructions: mov, str, ldr, add in class ARM, finally, write a print method for ARM that can display the registers and the memory locations that have been used. (make sure to make...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Hi, I am trying to create an XML JTree viewer using the DOM parser instead of...
Hi, I am trying to create an XML JTree viewer using the DOM parser instead of the SAX parser, I am having trouble changing my code in order to utilize the DOM parser to extract the XML data into the tree structure. Would you be able to explain what changes should be made to the code in order to use the DOM parser instead of the SAX parser? // Java Packages //      import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import...