You are on page 1of 12

Arizandy Rios

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.*;

public class Tester

public static void main(String args)

Scanner in=new Scanner(System.in);

System.out.print("Please enter your fullname:");

String name=in.nextLine();

for(int length=name.length()-1;length>=0;length--){

String reverse = name.substring(leng, leng+1);

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;

} while (v <= 195);

5. !done

6. no semicolon after do

7. it doesnt end it's an infinite #

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

12.while or for loop

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

make the code illegal.

5. it is legal

6. 39502

7. 91

8. 3359

9. int a = 0x5C3B;

System.out.println(a);

10. int k = 03365;

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

1. (A) Rectangle (B) myRect (C) double and int


2. public Rectangle(double int)
3. public Lunch((boolean diet, int cal)
{
boolean dietLunch =yummy5 ; calories =900;
}
4.(A) BankAccount (B)account39 (c) double
5.A class is like a cookie cutter. An object is like a cookie
6.public School(intd, String m)
7.(a) one class, many objects
8.the class
9. no house needs 2nd parameter to be boolean
10. a. int, b. int, c. double
11.BibleStory(String, int, double)
12.var1, var2, sss
13.void addParagraph(String)
String getPlotSummary()
String getSSS()
14.BibleStory philistine = new BibleStory(Ralph,19, 24.18);
15.BibleStory gravy = var.2
var.2 = 106.9
16.art. System.out.println(bart.getSSS());
17.<sss> jj = bart.sss;
18.public class Trail
{
private int x;
private int y;
private String s;
public Trail(String initialS) {
s = initialS;
x = 10;
y = 10;
}
public String met()
{
int d = x * y;
return + d;
}
}
19.public class peachyDandy
{
int z
}
20. it receives an int the double is 127.3

Project 16

public class Tester

public static void main(String args[])

Automobile myBmw = new Automobile(24);

myBmw.fillUp(20);

myBmw.takeTrip(100);

double fuel_left = myBmw.reportFuel();

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

public class Tester

public static void main(String args[])

Automobile myBmw = new Automobile(24);

myBmw.fillUp(20);

myBmw.takeTrip(100);

double fuel_left = myBmw.reportFuel();

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

1.double sgt[] = new int[800];

2. 21

3.double sgt[] = new double[799];

for (int j = 0; j < sgt.length; j++) {


sgt[j] = Math.sqrt(j);

System.out.println(sgt[j]);

4. shouldnt have parentheses after length

5.char cr[] = {'a', 'b', 'c', 'd', 'e'};

6. 5

7.int ref[] = new int[5];

int sumj=0;

for (int j = 0; j < ref.length; j++) {

ref[j] = (j * j);

sumj += ref[j];

System.out.println(sumj);

8. the variable k is not correctly placed

9.boolean bbc = heroWorship(dbx)

public boolean heroWorship( double vb)

10.56

11.23

12. error

13. makes values positive

14.1234

15.int pg[] = {1,-2,3,-4};

for (int jxx = 0; jxx < pg.length; jxx++){

if (pg[jxx]<0){

break;

}
}

System.out.println(s);

16.Wh

ping crane

17.fee fi fo

18.One two

19.String thlwrcase = "The best THERE is is Barth".toLowerCase();


String thsplit[] = thlwrcase.split("th");
int numboftokens = thsplit.length;
int numbofdelims = 0;
//System.out.println(thsplit.length);
boolean endfound = thlwrcase.endsWith("th");
if (endfound == true){
numbofdelims = numboftokens;
} else {
numbofdelims = numboftokens-1;
}

System.out.println("There are "+numbofdelims+" delimeters");

You might also like