# AP Computer Science Help



## dcf-joe (Oct 8, 2008)

I need help answering these questions. My Computer Science teacher does not teach us anything, but he gives us these humongous packets and then tests us over the material. None of us in the class can understand anything except Java basics, and I mean basic stuff like System.out.println. Anyways here are the questions:

 Which are the most commonly used number types in Java?
 When does the cast (long) x yield a different result from the call Math.round(x)?
 How do you round the double value x to the nearest int value, assuming that you know that it is less than 2 * 10^9?
 What is the difference between the following two statements? final double CM_PER_INCH = 2.54; and public static final double CM_PER_INCH = 2.54;
 What is wrong with the following statement? double circumference = 3.14 * diameter;
 What is the meaning of the following statement? balance = balance + amount;
 What is the value of n after the following sequence of statements? n--;  n++;  n--;
 What is the value of 1729 / 100? Of 1729 % 100?
 Why doesn't the following statement compute the average of s1, s2, and s3? double average = s1 + s2 + s3 / 3; //Error
 What is the value of Math.sqrt(Math.pow(x,2) + Math.pow(y,2)) in mathematical notation?
 Why can't you call x.pow(y) to compute x^y?
 Is the call System.out.println(4) a static method call?
 Assuming the String variable s holds the value "Agent", what is the effect of the assignment s = s + s.length()?
 Assuming the String variable river holds the value "Mississipi", what is the value of river.substring(1,2)? Of river.substring(2, river.length() - 3)?
 Why can't input be read directly from System.in?
 Suppose "in" is a Scanner object that reads from System.in, and your program calls String name = in.next(); What is the value of name if the user enters John Q. Public?


----------



## FooArm (Oct 9, 2008)

i am not going to sit here and answer this question for ... these are easy not hard try for once


----------



## Oliver_FF (Oct 9, 2008)

I'll answer all of these in 2 weeks after your deadline is up. Some are just too simple to explain without giving the answers away...

The Java API will help for a few of them:
http://java.sun.com/j2se/1.5.0/docs/api/

For q2 looking up Math.round() will help: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html#round(double)

For q12 this: http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html#println(int)


----------



## Castiel (Oct 13, 2008)

Hmmm.....When I need help on my Computer homework, I got Wikipedia.org to get all my answers!!!!!!!! Or try even gooogle!


----------



## Oliver_FF (Oct 22, 2008)

1.  Which are the most commonly used number types in Java?
int, long, double, float

   2. When does the cast (long) x yield a different result from the call Math.round(x)?
when x is a float, it returns an integer

   3. How do you round the double value x to the nearest int value, assuming that you know that it is less than 2 * 10^9?
cast it (int)x

   4. What is the difference between the following two statements? final double CM_PER_INCH = 2.54; and public static final double CM_PER_INCH = 2.54;
one is static so belongs to the class it is defined in. the other belongs to objects of its class.

   5. What is wrong with the following statement? double circumference = 3.14 * diameter;
i think 3.14 will be read as an inetger, needs to be 3.14d ?

   6. What is the meaning of the following statement? balance = balance + amount;
add amount to balance

   7. What is the value of n after the following sequence of statements? n--; n++; n--;
n-1

   8. What is the value of 1729 / 100? Of 1729 % 100?
wtf?

   9. Why doesn't the following statement compute the average of s1, s2, and s3? double average = s1 + s2 + s3 / 3; //Error
because you need brackets around s1+s2+s3

  10. What is the value of Math.sqrt(Math.pow(x,2) + Math.pow(y,2)) in mathematical notation?
square-root of [ x squared plus y squared ]

  11. Why can't you call x.pow(y) to compute x^y?
because pow is a static method of the Math class

  12. Is the call System.out.println(4) a static method call?
no

  13. Assuming the String variable s holds the value "Agent", what is the effect of the assignment s = s + s.length()?
s becomes "Agent5"

  14. Assuming the String variable river holds the value "Mississipi", what is the value of river.substring(1,2)? Of river.substring(2, river.length() - 3)?d
"is" and "ssissipi"

  15. Why can't input be read directly from System.in?
because the input is blocking?

  16. Suppose "in" is a Scanner object that reads from System.in, and your program calls String name = in.next(); What is the value of name if the user enters John Q. Public?
"John"


----------



## FordGT90Concept (Oct 23, 2008)

> What is the value of 1729 / 100? Of 1729 % 100?


It depends on what they are declared as.  If they are declared double, you'll get 17.29 and 29.  If they are declared int, you'll get 17 and 29.



> Why can't input be read directly from System.in?


It needs an instance.  That is, it needs an InputStream to read from.  When you read data from an InputStream, you are using methods of the instance.  Nothing in System.in is statically defined.


----------



## Skywalker12345 (Oct 23, 2008)

lol i dont understand any of this, im taking a college class at a technical campus for high school credit for computer matince and repair and its pretty easy and i get my a+ cert


----------



## AphexDreamer (Oct 23, 2008)

Wow I took computer Science AP and passed and I can't answer some of those question.

WOW down here in Texas were bad at that stuff lol. Please don't take this as spam.


----------



## a111087 (Oct 23, 2008)

I had AP computer science class and a teacher that was just there to look at us.  
I guess by taking AP class you should be prepared to study on your own.  Yes, it's not easy, that is why its called AP.  
All I have to say is do your best.  I didn't and I am sorry now.


----------



## FordGT90Concept (Oct 23, 2008)

AphexDreamer said:


> WOW down here in Texas were bad at that stuff lol. Please don't take this as spam.


About half the major game design studios are in Texas including Gearbox Software and Valve.


----------



## aximbigfan (Oct 23, 2008)

Why don't you sit down and think? 

I don't even know Java and I can solve pretty much all of these, granted I do have PHP/JS experience.

Chris


----------



## AphexDreamer (Oct 23, 2008)

FordGT90Concept said:


> About half the major game design studios are in Texas including Gearbox Software and Valve.



Would you look at that, I stand corrected.

Yes but I'm sure they learned their stuff from up North lol.


----------



## qamulek (Oct 23, 2008)

> 3. How do you round the double value x to the nearest int value, assuming that you know that it is less than 2 * 10^9?
> cast it (int)x



Actually not true since casting *should* just remove anything after the decimal place. 

Found this thread that discused some of the problems with converting floats to ints with the below quote specifically for rounding to nearest integers:



> Try adding 0.5 to the floating point number before converting to int. The truncation will cause it to be rounded to the correct value. For instance your 20.9 will become 21.4 and be truncated down to 21. This is a pretty standard trick :yes:


----------

