Answer to Monday's Literal Programming Question
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.");
}
}


No comments yet. Leave a Comment