Computer Science  >  STUDY GUIDE  >  MathTrick.java Florida Virtual School COMPUTER SCIENCE 0200320-61 (All)

MathTrick.java Florida Virtual School COMPUTER SCIENCE 0200320-61

Document Content and Description Below

/** * * @author Aaron Williams * @version 12/05/21 * * Program uses methods to manipulate integers and strings. * */ public class MathTrick { /** * ****** DO NOT USE ARRAYS OR CON ... VERT NUMBERS TO STRING UNTIL STEP 7 ****** * */ // Step 1) Creates a random 3 digit (100-999) number where the first and last digit differ by more than one // Hint: Use Math.random() to create number in the correct range // use modulus to find the last digit and divide by 100 for the first digit. // calculate the difference, which method can you use so it doesn't matter how the numbers are subtract? // while the difference of the digits is less than 2, create a new random number and try again public static int getRandomNum() { int maxNum = 999; int minNum = 100; int num = 0; int firstDigit = 0; int lastDigit = 0; // complete the method while(Math.abs(firstDigit - lastDigit) < 2) { num = (int)(Math.random() * (maxNum - minNum + 1) + minNum); firstDigit = num / 100; lastDigit = num % 10; } return num; } // Step 2 & 4) reverse the digits of a number // Hint: to reverse a number without converting it to a String: // create a new variable to store the reversed number // while the original number > 0 // for each digit, multiply the new variable by 10 (to make room for the new digit) // then add the last digit (remember modulus?) to the new variable // divide the original number by 10 to get rid of the last digit // Ex: 584--> (0 x 10) + 4 = 4 ; 58--> (4 x 10) + 8 = 48; 5-->(48 x 10) + 5 = 485 public static int reverseDigits (int num) { int num2 = 0; while(num > [Show More]

Last updated: 3 years ago

Preview 1 out of 3 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of MathTrick.java Florida Virtual School COMPUTER SCIENCE 0200320-61 document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$5.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

128
0

Document information


Connected school, study & course


About the document


Uploaded On

Nov 20, 2022

Number of pages

3

Written in

All

Seller


Profile illustration for Browsegrades
Browsegrades

Member since 3 years

0 Documents Sold

Additional information

This document has been written for:

Uploaded

Nov 20, 2022

Downloads

 0

Views

 128

Document Keyword Tags

Recommended For You

Get more on STUDY GUIDE »

$5.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·