banner



Consider The Following Code Snippet

The Java TM Tutorial
Previous Page Lesson Contents 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

  1. Consider the post-obit code snippet:
    arrayOfInts[j] > arrayOfInts[j+1]              
    Question: What operators does the code incorporate?
    Answer: [], >, [], +
  2. Consider the following code snippet:
    int i = 10; int n = i++%5;              
    1. Question: What are the values of i and n subsequently the code is executed?
      Answer: i is eleven, and n is 0.]
    2. Question: What are the concluding values of i and north if instead of using the postfix increase operator (i++), you use the prefix version (++i))?
      Answer: i is 11, and n is ane.
  3. Question: What is the value of i after the following code snippet executes?
    int i = 8; i >>=2;              
    Answer: i is two.
  4. Question: What is the value of i after the following lawmaking snippet executes?
    int i = 17; i >>=one;              
    Answer: i is 8.

Exercises

  1. 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  (in a .java source file)
  2. 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  (in the API reference documentation) course, which is discussed in Formatting Numbers with Custom Formats (in the Learning the Java Language trail)
    Solution: CurrencyExchange  (in a .java source file)
  3. 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 of condition. For example, if status is 1 (only bit 0 is fix) the program should print something like this:
    ready to receive requests              
    1. Practice: Testify your code.
      Solution: Bits  (in a .java source file)
    2. Exercise: What is the output when status is viii?
      Solution:
      unrecoverable error occurred                  
    3. Do: What is the output when status is 7?
      Solution:
      ready to receive requests processing a request error recovery in progress                  

Previous Page Lesson Contents 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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel