1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy
Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Answer to Monday's Literal Programming Question

Sunday December 7, 2008

Monday's question was a simple look at using hexadecimal and octal literals in the scope of a for loop declaration. The program needed to have a for loop that iterated from 0xEF to 0647, a total of 185 times.

Here's my version:

Note: This loop is really the same as giving the int variable i the starting value of 239 (the denary value of 0xEF) and iterating until it equals the value of 423 (the denary value of 0647).

public class HexOctalLoop {

  public static void main(String[] args) {

    int count = 0;
    for (int i = 0x0EF; i <= 0647; i++)
    {
      count++;
    }
    System.out.println("The loop looped " + count + " times.");
  }
}
Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Discuss
Community Forum
Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java

©2009 About.com, a part of The New York Times Company.

All rights reserved.