Shadow7874
10+ year member
Member
Well im trying to get my homework done for school tuesday but it seems my book is MIA so ive only been able to answer what i remember from class.
If anyone can check my answers or help with answering and explaining the others that would rock.
I wont be at my comp for the next few hours of so but any help is greatly appreciated
If anyone can check my answers or help with answering and explaining the others that would rock.
I wont be at my comp for the next few hours of so but any help is greatly appreciated
Assignment 1 Chapter 3
Ex 3.1
Write a statement that prints the number of characters in a String object called overview.
Ex 3.2
Write a statement that prints the 8th character of a string object called introduction.
My Answer:
System.out.println = Introduction.substring (8,8);
Ex 3.3
Write a declaration for a String variable called change and initialize it to the characters stored in another String object called original with all ‘e’ characters changed to ‘j’.
My Answer:
Change = original.replace (‘e’, ‘j’));
Ex 3.4
What output is produced by the following code fragment?
String m1, m2, m3;
M1 = ”Quest for the Holy Grail”;
M2 = m1.toLowercase();
M3 = m1 + “ “ + m2;
System.out.println (m3.replace(‘h’, ‘z’));
My Answer:
Quest for tze Holy Grail quest for tze zoly grail
Ex 3.5
What is the effect of the following import statement?
Import java.awt.*;
My Answer:
The java Abstract Windowing Toolkit is imported.
Ex 3.6
Assuming that a Random object has been created called generator, what is the range of the result of each of the following expressions?
a. generator.nextInt(20)
b. generator.nextInt(8) + 1
c. generator.nextInt(45) + 10
d. generator.nextInt(100) – 50
Ex 3.7
Write code to declare and instantiate and 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.
a. 0 to 100
b. 0 to 500
c. 1 to 10
d. 1 to 500
e. 25 to 50
f. –10 to 15
Ex 3.8
Write an assignment statement that computes the square root of the sum of num1 and num2 and assigns the result of num3.
Ex 3.9
Write a single statement that computes and prints the absolute value of total.
Ex 3.10
Write code statements to create a DecimalFormat object that will round a formatted value to 4 decimal places. Then write a statement that uses that object to print the value of result, properly formatted.