Results 1 to 7 of 7
- 01-30-2011, 10:10 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 10
- Rep Power
- 0
A basic method with an unexpected output
I have a very basic piece of code here that is acting strangely. What the code should do: prints a range of numbers and a character beside each number, one per line.
Here is the code:
Java Code:public class CharacterClass { public static void RangeOfChars(int lowrange, int highrange) { System.out.println("====================="); for(int i=lowrange; i<=highrange; i++) System.out.println(i + " " + (char)i); System.out.println("====================="); } }
But when I run this method using the method call RangeOfChars(0,100) I get the following output:
Java Code:< This line is left blank > 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ 96 ` 97 a 98 b 99 c 100 d =====================
What happened to numbers 0-12 and why aren't they listed above?
- 01-30-2011, 10:21 PM #2
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
Since Unicode developed from ANSI, which in turn developed from ASCII, it has the same non-printable characters at the start of its character set.
Wikipedia: ASCII control characters
- 01-31-2011, 03:26 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 10
- Rep Power
- 0
Last edited by JONCOM; 01-31-2011 at 03:30 AM.
- 01-31-2011, 03:32 AM #4
2 options
Perhaps the input to the RangeOfChars method is not 0 as you expect.
Priobably more likely is that there is so much output that the first few lines have scrolled off the page and is no longer viewable. Try redirecting output to a file so you can see it all.
Java Code:C:\Directory>java ProgramName > output.txt
Last edited by Junky; 01-31-2011 at 03:40 AM.
- 02-01-2011, 05:28 AM #5
Member
- Join Date
- Jan 2011
- Posts
- 10
- Rep Power
- 0
- 02-01-2011, 06:22 AM #6
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
That's not code, but a command prompt instruction. Did you jump straight to an IDE, no notepad + command prompt to get you started?
Ever seen a dog chase its tail? Now that's an infinite loop.
- 02-01-2011, 07:25 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Character 0x0c (decimal 12) is the 'form feed' character and it clears the screen on some terminals. So, characters 0, 1, 2, ... 11 are printed, then the screen is cleared and the characters in the range 13, 14, ... are printed.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Basic Circular Linked List - addFirst() method works improperly
By carlodelmundo in forum New To JavaReplies: 9Last Post: 11-04-2011, 03:09 AM -
What will be output by the following code? using trim method.
By racewithferrari in forum New To JavaReplies: 4Last Post: 11-17-2009, 09:40 PM -
ASAP PLZ- Having problems with basic pattern input/output
By ZetaPunk in forum New To JavaReplies: 3Last Post: 09-22-2009, 05:16 AM -
Question about File renameTo() method : Abnormal output
By suvojit168 in forum New To JavaReplies: 1Last Post: 07-25-2009, 08:22 PM -
invoking method and output questions
By bluekswing in forum New To JavaReplies: 1Last Post: 08-06-2007, 06:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks