Answered step by step
Verified Expert Solution
Question
1 Approved Answer
help, this is for dr java? Problem 11) Write a code fragment, using nested for-loops, whose output in the console will look like the following.
help, this is for dr java? Problem 11) Write a code fragment, using nested for-loops, whose output in the console will look like the following. Your code fragment does not need to be a complete program, it just needs to output these six lines. (Hint: Don't try to compute the output numbers from the loop indices. To get the output numbers, just have a counter that counts up from 10, and print out the counter.) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
Problem 21) Suppose that someone has defined for us a class called Random. For each of the following parts, write a single line of Java code that does what is described by the sentence. (a) Declare r to be a reference variable of type Random and assign to r a Random object. (b) Send the object named r the nextDouble message (which tells the object to compute a random number) and have the result printed in a console window. (c) Declare a variable of type int and assign to it the result of sending the object named r the nextInt message with parameter 10. (d) Create a String object containing the text "This is so much fun" and send the object the subString message with parameters that extract the first eleven letters of the string. Assign the result of this calculation to a variable called str which is declared to be of type String. (e) Send the object named str the concat message with parameter "easy". To the result of this calculation, send the toUpperCase message. (`concat' is an abbreviation for concatenate, which means to put the string "easy" at the end of the string named by str.)
Problem 23) The following questions refer to the Rectangle class shown below. class Rectangle { private int width; private int height; public Rectangle(int w, int h) { width = w; height = h; } public int getWidth() { return width; } public int getHeight() { return height;} public void setWidth(int w) { width = w; } public void setHeight(int h) { height = h;} public int computeArea() { return width * height; } } (a) After the following statements have been executed, how many Rectangle objects will exist, not counting garbage objects? Explain your answer. Rectangle rect1 = new Rectangle(100,200); Rectangle rect2 = new Rectangle(50,75); Rectangle rect3 = rect2; rect2 = rect1; rect1 = null; (b) After the following statements have been executed, how many Rectangle objects will exist, not counting garbage objects? Explain your answer. Rectangle rect1 = new Rectangle(200,50); Rectangle rect2 = new Rectangle(100,100); Rectangle rect3 = rect2; rect2 = null; rect1 = rect2;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started