|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

01-15-2008, 10:17 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
Tough Homework Questions, PLEASE HELP!
Hello! I’m fairly new to the forum and I was wondering if I could get some help with a couple of tough homework questions that I have to do. If you could also provide a brief explanation that would be great but you don’t have to. Thanks soo much!!!
1. What will print to screen?
System.out.println(Object1);
a. Hexidecimal code of the object's source code
b. Object1's Class name and Object1's memory address
c. Nothing
2. Which of the following is a literal string?
a. new String(a)
b. String
c. Char String
d. "Hello Philip"
3. What is the purpose for the following code segment?
somevariable = expression;
a. creates a method
b. compares values
c. an assignment operation
d. finds the variable in the expression
4. Which is a variable declaration only?
a. final float = 12;
b. private int MyNumber = 67;
c. char Initial;
d. int Age = 55;
5. Which of the following are valid commands? (MORE THAN ONE ANSWER!)
a. System.out.println("The amount is " + 99);
b. String values = 98 + 45;
c. String numbers = "7.8" + " 9.0 " + " 3.4 ";
d. String money = "$" + 45.90 + 22.45;
6. What primitive data type should be used for the following value?
true
a. float
b. Boolean
c. char
d. int
7. What type of constant is '-49'? (POSSIBLY MORE THAN ONE ANSWER!)
a. neither
b. symbolic
c. literal
d. both
8. If a decimal is changed to an int, _________.
a. The decimal is truncated
b. it cannot be changed
c. The decimal is rounded up
d. the decimal is rounded down
9. What is the output?
System.out.println("my numbers: " + 4 + 5);
a. my numbers:
b. invalid command error
c. my numbers: 45
d. my numbers: 9
|
|

01-15-2008, 10:56 PM
|
 |
Moderator
|
|
Join Date: Jan 2008
Location: Dallas
Posts: 263
|
|
|
these aren't no tough questions
__________________
dont worry newbie, we got you covered.
|
|

01-15-2008, 11:52 PM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by passage
Hello! I’m fairly new to the forum and I was wondering if I could get some help with a couple of tough homework questions that I have to do. If you could also provide a brief explanation that would be great but you don’t have to. Thanks soo much!!!
You're joking, right? Usually I welcome people to our forums graciously... in your case, you've started off the wrong way. You need to attempt these yourself. These are your questions, your homework - not ours.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. !
Got a little Capt'n in you? (drink responsibly)
|
|

01-15-2008, 11:57 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
these questions are 9 out of 60 total... these are just the ones I had trouble with =/
|
|

01-15-2008, 11:58 PM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by passage
these questions are 9 out of 60 total... these are just the ones I had trouble with =/
How about you tell us what you're beliefs are on each one and why you would choose one answer over another.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. !
Got a little Capt'n in you? (drink responsibly)
|
|

01-16-2008, 02:07 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
I mean this in a non-insulting way, but.. I don't understand how you can have 60 questions and get stuck on 9 of the most basic questions. How basic were the other questions?
__________________
//Haha javac, can't see me now, can ya?
|
|

01-16-2008, 02:21 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
Um they pretty easy/basic.. these were basically the ones that I couldn't find the answers to in the textbook.. that's why I'm lost..
|
|

01-16-2008, 03:10 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
like...
1. i have absolutely no idea, the text does not specify.
2. im assuming it's c b/c Char signifies 1 character right? and String is 1 character
3. i know it does not create a method.. but otherwise all i really know is that it is a declaration which is signified by the ;
4. the text does not provide examples of a variable declaration
5. i'm totally lost on this one ..
6. since true is one character im guessing you use char?
7. im pretty sure it's both
8. i just know that the decimal is not rounded up.. otherwise..
9. i know it isn't the one with "9".. is it my numbers: 45?
I know this is my homework.. but this AP Java Class is killing me this year and the text is very hard to follow as I have no background in Java and was forced into the class. I would really appreciate anyone's help. Thanks a lot.
|
|

01-16-2008, 03:22 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
What book are you using? It sounds like a piece of trash the way you describe it lol. Let me explain some things, and see if you can come up with the answers. System.out.println() calls toString() on its parameters (which are the things inside of the parentheses). Now, if a certain object does not have a toString() method defined, the default is that it prints the class name and memory location. Let's say that Object1 is a class. If i define toString() in this class to make it so that it prints out a number, calling System.out.println(Object1) is going to print whatever you defined toString() to be. I wouldn't worry about this too much, as you are still learning the basics, but just know that, by default, toString() prints the class name and memory location.
Using the equals sign is assigning the first expression to the second.
Variable declaration is just creating a new variable but not defining it.
With this knowledge in mind, see if you can do the questions. Otherwise, look up these things online. Your book must really be crappy because these are all basic concepts that must be grasped.
__________________
//Haha javac, can't see me now, can ya?
|
|

01-16-2008, 03:27 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
then 1 is b?
|
|

01-16-2008, 03:31 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
Yes, it is
__________________
//Haha javac, can't see me now, can ya?
|
|

01-16-2008, 03:35 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
thanks a lot! lol.. 1 down.. 8 to go
|
|

01-16-2008, 04:23 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
i figured out that true would certainly be a boolean primitive data type b.c the range for bollean is true or false.... can anyone explain number 3 for me... the text just mentions that it is a declaration, nothing more =/
|
|

01-16-2008, 04:27 AM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by gibsonrocker800
Using the equals sign is assigning the first expression to the second.
Hmm... what do you think passage?
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. !
Got a little Capt'n in you? (drink responsibly)
|
|

01-16-2008, 04:30 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
Gonna go with c. an assignment operation..
|
|

01-16-2008, 04:36 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
4. Which is a variable declaration only?
a. final float = 12;
b. private int MyNumber = 67;
c. char Initial;
d. int Age = 55;
i know it's not b...
the book says a declaration always ends with a semi-colon, which they all do... it also says that public or private cannot be used in declarations of local variables.. which is why i obviously ruled out b.
i also know that an initialized final "variable" is not actually a variable but it's really a constant because when it's declared final.. the values cannot change. that leaves me with c. and d.
i wanna say int Age = 55; because char Initial; looks incorrects but i need further explanation
|
|

01-16-2008, 11:46 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
Trick question
Hi passage
The modifiers (final and private) are there to confuse you. The question said:
Originally Posted by passage
Which is a variable declaration only?
Look at them all. Each one declares a variable but only one does not get initialized.
c. char Initial; // <- see no equal sign
Hope this helped 
__________________
If your ship has not come in yet then build a lighthouse.
|
|

01-17-2008, 12:17 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
passage, you need to buy a new book. I've never heard of a book that just doesn't explain assignment. or variable initialization. What book are you using (i'd like to purchase one so i can burn it, unless... the book is ok but you're not understanding it).
__________________
//Haha javac, can't see me now, can ya?
|
|

01-17-2008, 12:20 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
Thanks for all the help guys.. I worked some of the problems out and i got a 95% on the homework :]
|
|

01-17-2008, 12:21 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
umm im using Java Methods A & AB: by litvin and litvin.. i think its a more advanced book and i have no background in java.. it's meant for an AP Java Class
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|