AP Computer Science: Worksheet Overviews

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the output? String s = "Lucky hockey puck"; String m = "uck"; int j = 6, z = 99; int k = s.indexOf(z); System.out.println(k);

2

Is the following code legal? If so, what is printed? If not, why? int k = 7; k*=.5; System.out.println(k);

3

String sam = "hey there"; String ben = "hey thar"; out.println( ben.compareTo(sam) ); What's the output?

-4

What is the output? String s = "Lucky hockey puck"; String m = "uck"; int j = 6, z = 99; int k = s.indexOf(m); System.out.println(k);

1

What is the output? String str = "Hello World!"; str.substring(6); System.out.println(str);

Hello World!

Which of these expressions will evaluate to true? String s1 = "Java"; String s2 = new String("Java"); String s3 = sl; System.out.println( <place expression here> ); I. s1 == s2 II. s1.equals(s2) III. s3.equals(s2)

II and III

Given the following, which of the following is true? String m = "Brady"; String n = "Brad"; String p = "Brave"; I. m.compareTo(n) < 0 II. m.compareTo(p) < 0 III. p.compareTo(n) < 0

II only

When asked for indexOf(blah blah blah), if it's a number....

It's literally asking if the number is in the string

What is the output? String s = "Lucky hockey puck"; String m = "uck"; int j = 6, z = 99; String str = s.replace('o', 'p'); System.out.println(str);

Lucky hpcky puck

When an object no longer has any reference variables referring to it, what happens to it?

The garbage collector makes the memory it occupies available for new objects.

What is the output? String s = "UNIVERSITY ", t=""; s += "INTERSCHOLASTIC "; s += "LEAGUE"; t = s.substring(3,4); t += s.substring(21,22); t += s.substring(5,s.indexOf(" ")); System.out.print(t);

VARSITY

What is the range of Math.random();

[0,1)

What is the range of the code below: System.out.print( Math.random()*10 );

[0,10)

What is the range of the code below: System.out.print(Math.random()*20+10 );

[10,30)

Math.abs stands for

absolute value

String x = "Java"; String y = new String("Java"); out.println((x == y) + " " + x.compareTo(y)); What's the output?

false 0

Write code that will create a constant E that's equal to 2.718.

final double E = 2.718;

Write the simplest type constant that sets the number of students, NUM_STUDENTS,to 236.

final int NUM_STUDENTS = 236;

String s = "cdefghijklmnop"; out.print(s.substring(4));

ghijklmnop

--is the import needed to use Scanner.

import java.util.Scanner;

Write a line of code in which you divide the double precision number d by an integer variable called i. Type cast the double so that strictly integer division is done. Store the result in j, an integer.

int j = (int)d/i

-- is the Scanner method used to input a one word String.

next()

-- is the Scanner method used to input a double.

nextDouble()

-- is the Scanner method used to input an integer.

nextInt()

-- is the Scanner method used to input a one line String.

nextLine()

What value is assigned to a reference variable to show that there is no object?

null

String q; q = "Do or do not, there is no try"; q = q.substring(q.length()/2,18); System.out.println(q); What's the output?

ther

String dl = new String("3.7"); String d2 = dl; String d3 = "3.7"; out.print( (dl == dl) + " "); out.print( (d2 == d3) + " "); out.println(dl.equals(d3));

true false true

Is double f4 = 22; legal?

yes


संबंधित स्टडी सेट्स

Chapter 23: Conditions Occurring After Birth

View Set

Chapter 7: Voting, Elections, and Political Participation

View Set

Disorders of Special Sensory Function-Chapter 38

View Set

Practice Ch. 5 Integumentary System

View Set

Lippincott NCLEX Personality and Substance-Related Disorders

View Set

Permission, obligation and necessity

View Set

CCNA Routing&Switching 200-125 (part 4)

View Set

Chapter 20: Alteration in Bowel Elimination/Gastrointestinal Disorder

View Set