Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why won't a casted char be printed?

 
Ranch Hand
Posts: 113
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The following code snippet has been taken from one of Enthuware's mock exams, and I edited it for scientific purposes. The exam question isn't relevant for this thread.



I would expect something like this to be printed: "Input value must be smaller than 10" (or some other value for 10, depending what character is created). It doesn't, however. It simply prints "Input value must be smaller than" followed by two white lines.

So x doesn't seem to be parsed into the String msg properly. Why does this happen? Is it because of some encoding issue I don't know about? How could the char x be parsed so that it will become part of msg? I get similar results when I try other numbers than 10; my console shows unknown characters.

Note: I don't know if I need to know this for the exam. This question is actually about assigning String objects, but I got sidetracked and wondered what would happen if the assignment would be done properly.

Thanks!

Regards,
Shane
 
author
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shane Jensen wrote:
I would expect something like this to be printed: "Input value must be smaller than 10" (or some other value for 10, depending what character is created). It doesn't, however. It simply prints "Input value must be smaller than" followed by two white lines.

So x doesn't seem to be parsed into the String msg properly. Why does this happen? Is it because of some encoding issue I don't know about? How could the char x be parsed so that it will become part of msg? I get similar results when I try other numbers than 10; my console shows unknown characters.



A character with an ASCII code of 10 is a line feed. In Windows speak, this should move the cursor down by one. In Unix speak, this should move the cursor down by one and back to the first column.

Henry
 
Rebecca Wolf
Ranch Hand
Posts: 113
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Henry Wong wrote:

Shane Jensen wrote:
I would expect something like this to be printed: "Input value must be smaller than 10" (or some other value for 10, depending what character is created). It doesn't, however. It simply prints "Input value must be smaller than" followed by two white lines.

So x doesn't seem to be parsed into the String msg properly. Why does this happen? Is it because of some encoding issue I don't know about? How could the char x be parsed so that it will become part of msg? I get similar results when I try other numbers than 10; my console shows unknown characters.



A character with an ASCII code of 10 is a line feed. In Windows speak, this should move the cursor down by one. In Unix speak, this should move the cursor down by one and back to the first column.

Henry


Hi Henry,

Alright, that's close to what I thought. Thanks for the confirmation.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shane Jensen wrote:I would expect something like this to be printed: "Input value must be smaller than 10" (or some other value for 10, depending what character is created). It doesn't, however. It simply prints "Input value must be smaller than" followed by two white lines.


Try with a value above 32 and be amazed
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic