HW3 - Katherine Kahla CompSci 125 001 HW3 3.7. Write code...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Katherine Kahla CompSci 125 – 001 HW3 3.7. Write code to declare and instantiate an object of the Random class (call the object reference variable rand). Then write a list of expressions using the nextInt method that generates random numbers in the following specified ranges, including the endpoints. Use the version of the nextInt method that accepts a single integer parameter. Random rand = new Random(); a. 0 to 10 rand.nextInt(11); b. 0 to 500 rand.nextInt(501); c. 1 to 10 rand.nextInt(10) + 1; d. 1 to 500 rand.nextInt(500) + 1; e. 25 to 50 rand.nextInt(26) + 25 ; f. -10 to 15 rand.nextInt(26) - 10; 3.8 . Write an assignment statement that computes the square root of the sum of num1 and num2 and assigns the result to num3. num3 = Math.sqrt( num1 + num2 ); 3.10. Write code statements to create a DecimalFormat object that will round a formatted value to 4 decimal values. Then write a statement that uses that object to print the value of result, properly formatted. DecimalFormat fmt = new DecimalFormat(“0.####”);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/22/2012 for the course COMPSCI 125 taught by Professor Cole during the Spring '12 term at Boise State.

Page1 / 2

HW3 - Katherine Kahla CompSci 125 001 HW3 3.7. Write code...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online