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: 1 year ago

Preview 1 out of 3 pages

Add to cart

Instant download

We Accept:

We Accept
document-preview

Buy this document to get the full access instantly

Instant Download Access after purchase

Add to cart

Instant download

We Accept:

We Accept

Reviews( 0 )

$5.00

Add to cart

We Accept:

We Accept

Instant download

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

OR

REQUEST DOCUMENT
70
0

Document information


Connected school, study & course


About the document


Uploaded On

Nov 20, 2022

Number of pages

3

Written in

Seller


seller-icon
Browsegrades

Member since 2 years

0 Documents Sold


Additional information

This document has been written for:

Uploaded

Nov 20, 2022

Downloads

 0

Views

 70

Document Keyword Tags

What is Browsegrades

In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

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 © Browsegrades · High quality services·