I've been coding in C/C++ and VB for close to 20 years. I've been teaching C++ for about 8 and VB.NET for the past year. In the process of trying to learn Java and just trying to write a simple program to do console I/O. I've got two texts that I'm using as a reference and one uses their own class for doing input - I'd rather avoid specialized classes and get down to the roots of what their class is doing. The other text uses lines like this:
to perform character input but when I try compiling it I'm getting exceptions. I wrap the exception causing code in a try/catch block and the subsequent lines start throwing exceptions because "Letter might not be initialized"?!?
Doesn't java have a single line command for doing input like C/C++/VB?
Code:
char Letter;
Letter = (char)System.in.read();
to perform character input but when I try compiling it I'm getting exceptions. I wrap the exception causing code in a try/catch block and the subsequent lines start throwing exceptions because "Letter might not be initialized"?!?
Doesn't java have a single line command for doing input like C/C++/VB?
Code:
[COLOR=green]/* C */[/color]
char Letter;
Letter = getch();
Code:
[COLOR=green]// C++[/color]
char Letter;
cin >> Letter;
Code:
[COLOR=green]'VB.Net[/color]
Dim Letter As Char
Letter = Convert.ToChar(Console.ReadLine())