Consider The Following Code Snippet
The Java TM Tutorial
Trail: Learning the Java Language
Lesson: Language Basics
Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Course |
Trail: Learning the Java Language
Lesson: Language Basics
Answers to Questions and Exercises: Operators
[Pending: This page has not however been updated.]
Answers to Questions
- Consider the post-obit code snippet:
Question: What operators does the code incorporate?arrayOfInts[j] > arrayOfInts[j+1]
Answer:[]
,>
,[]
,+
- Consider the following code snippet:
int i = 10; int n = i++%5;
- Question: What are the values of
i
andn
subsequently the code is executed?
Answer:i
is eleven, andn
is 0.]- Question: What are the concluding values of
i
andnorth
if instead of using the postfix increase operator (i++
), you use the prefix version (++i)
)?
Answer:i
is 11, andn
is ane.- Question: What is the value of
i
after the following code snippet executes?Answer:int i = 8; i >>=2;i
is two.- Question: What is the value of
i
after the following lawmaking snippet executes?Answer:int i = 17; i >>=one;i
is 8.
Exercises
- Exercise: Write a program that tests whether a floating point number is zero. (Hint: You shouldn't generally use the equality operator
==
with floating betoken numbers, since floating signal numbers by nature are hard to match exactly. Instead, test whether the number is shut to zero.)
Solution:FloatTest
- Exercise: Write a plan that calculates the number of US dollars equivalent to a given number of euros. Presume an exchange charge per unit of 0.781162 euros per dollar. If you want to command the format of the numbers your program displays, y'all can use the
DecimalFormat
course, which is discussed in Formatting Numbers with Custom Formats
Solution:CurrencyExchange
- Write a program that uses the $.25 in a unmarried integer to stand for the truthful/simulated data shown in the following figure:
Include in the programme a variable named status
, and accept the program print the meaning ofcondition
. For example, ifstatus
is 1 (only bit 0 is fix) the program should print something like this:ready to receive requests
- Practice: Testify your code.
Solution:Bits
- Exercise: What is the output when status is viii?
Solution:unrecoverable error occurred- Do: What is the output when status is 7?
Solution:ready to receive requests processing a request error recovery in progress
Kickoff of Tutorial > Start of Trail > Showtime of Lesson | Search Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.
Consider The Following Code Snippet,
Source: http://www.iitk.ac.in/esc101/05Aug/tutorial/java/nutsandbolts/QandE/answers_operators.html
Posted by: parkerthavercuris.blogspot.com
0 Response to "Consider The Following Code Snippet"
Post a Comment