Professional Documents
Culture Documents
Ap Computer Science-2
Ap Computer Science-2
AP Computer Science
Period 3
Mr.Shattuck
Exercises 11
1.5
2.7
3.56
4.3-24
5.19-28
6.101.01
7. for (int i = 1; i <= 8; i = i * 2)
{
System.out.println(3 * i);
}
8.for (int i = 8; i >= 1; i = i / 2)
{
System.out.println(3 * i);
}
9. 5
10.Control expression
11.5,10,15,20,25,30,35,40,45,50
12.16
13.have an infinite loop
14.137
Project
import java.util.*;
String name=in.nextLine();
for(int length=name.length()-1;length>=0;length--){
System.out.print(reverse.toLowerCase());
Exercises 12
1. while ( )
2. do
{
}
while ( );
3. int m = 97;
while (m<=195)
k=k*k+3*m;
p=p+m+1;
m++;
4. do
k = k * k + 3 * v;
q = Math.sqrt(q + v + 1);
v *= 3;
5. !done
6. no semicolon after do
8.76
9.semicolon on the first line & the last line shouldnt have the semicolon
10.0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 3,0 3,1 3,2
11. while
13.94
14. public static void main(String[] args)
{
do
{
System.out.print(Please enter an integer: ");
int input = Keyboard.readInt();
System.out.println(input * input);
} while (input != 0);
}
EXERCISES 13
1. 65
2. 90
3. 97
4. 122
5. 26
6. 48
7. 57
8. ABCDEFGHIJKLMNOPQRSTUVWXYZ
9. alfred e. neuman
10. char a = K;
String s = + a;
11. String p = W;
char a = s.charAt(0);
12. no
13.yes
14. no
15.69
16.E
17. cv = Character.toUpperCase(boy);
18.cv = Character.toLowerCase(boy);
19.Character.isDigit(bv)20.
20.Character.isLetter(bv)]
21.Character.isUpperCase(bv)
22.Character.isLetterOrDigit(bv)
23.Character.isLowerCase(bv)
24.This code prints the ASCII values for any whitespace characters (new line character, space
and tabs are whitespace).
Exercise 14
1. 43089 dec
2. 35
3. 415
4. illegal b/c the value for octal only goes up to 0-7 and there is a 9 present which would
5. it is legal
6. 39502
7. 91
8. 3359
9. int a = 0x5C3B;
System.out.println(a);
System.out.println(k);
11. 0111011110
12. 162E
13. 13056
14. aeba
15. 4423
16. 10
17. 8
18. base is 16
19. 10
20. base is 2
21. 11000110
22. 10100010
23. the 10 is the binary code for 2, so they mean that there are 2 types of people rather than 10
24. System.out.println(Integer.parseInt("1000101",2));
25.
26. 127DE
27. 43365363
28. 1650022
29. 160A
30. 9
Exercise 15
Project 16
myBmw.fillUp(20);
myBmw.takeTrip(100);
System.out.println(fuel_left);
Exercises 16
1. true
2. true
3. true
4. false
5. false
6. legal
7. nope , its private
8. legal
9. legal
10. nope needs a class
11. nope method 2 is private
12. public class Surfer
{
public surfer Dude
13. A
14. 2500
15. theres has to be an equal sign
16.the objects wouldnt equal
17. Yellow
Project
myBmw.fillUp(20);
myBmw.takeTrip(100);
System.out.println(fuel_left);
}
}
Exercises 17
1. true
2. true
3. true
4. false
5. false
6. legal
7. nope , its private
8. legal
9. legal
10. nope needs a class
11. nope method 2 is private
12. public class Surfer
{
public surfer Dude
13. A
14. 2500
15. theres has to be an equal sign
16.the objects wouldnt equal
17. Yellow
Exercises 18
2. 21
System.out.println(sgt[j]);
6. 5
int sumj=0;
ref[j] = (j * j);
sumj += ref[j];
System.out.println(sumj);
10.56
11.23
12. error
14.1234
if (pg[jxx]<0){
break;
}
}
System.out.println(s);
16.Wh
ping crane
17.fee fi fo
18.One two