Results 1 to 7 of 7
  1. #1
    JONCOM is offline Member
    Join Date
    Jan 2011
    Posts
    10
    Rep Power
    0

    Default 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?

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    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

  3. #3
    JONCOM is offline Member
    Join Date
    Jan 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Iron Lion View Post
    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

    I still don't understand why 0-12 aren't at the very least displaying a number.

    On the other hand then, why are 13-32 displaying numbers at all?

    PS - I did follow your link. But that doesn't explain this behavior, does it?
    Last edited by JONCOM; 01-31-2011 at 03:30 AM.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    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.

  5. #5
    JONCOM is offline Member
    Join Date
    Jan 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    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

    I don't think that code you gave me compiles, and I'm not sure what minor (or major) tweaks will make it compile. Would you mind giving me the code to direct my output to a text file so I can try out your suggestion?

    Thanks.

  6. #6
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    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.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default

    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 9
    Last Post: 11-04-2011, 03:09 AM
  2. What will be output by the following code? using trim method.
    By racewithferrari in forum New To Java
    Replies: 4
    Last Post: 11-17-2009, 09:40 PM
  3. Replies: 3
    Last Post: 09-22-2009, 05:16 AM
  4. Question about File renameTo() method : Abnormal output
    By suvojit168 in forum New To Java
    Replies: 1
    Last Post: 07-25-2009, 08:22 PM
  5. invoking method and output questions
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 06:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •