/* works.
CIS 790 JAVA PROGRAMMING PROF. AUCIELLO
p30a4.java p30a4.html
TOPICS: Classes
System Input (kb) & Output (display)
Character Conversion (char) = int to char.
-- (char) changes int to char.
Error-Trapping {try.. catch..} = [Exception]
|| = or (note this!). && = and.
System.in.read() will wait for an int input!
(= Console.readInt)
Boolean AND, NOT
branching - break out of loop.
Output:
ASCII Char: (// to exit) 1 ASCII Code: 49
ASCII Char: (// to exit) 2 ASCII Code: 50
ASCII Char: (// to exit) 3 ASCII Code: 51
ASCII Char: (// to exit) a ASCII Code: 97
ASCII Char: (// to exit) z ASCII Code: 122
ASCII Char: (// to exit) A ASCII Code: 65
ASCII Char: (// to exit) // Exiting Program. inInt = 47
*/
import corejava.*;
import java.io.*; // "java.io" is part of the class library
// (classes.zip). It contains the routines
// (macros) required for IO Exception and
// system Input / Output.
// comment it out to see what happens.
// Links to a class called 'java.io.*'
// This class-name (p30a2) must be defined in a file
// called "p30a2.java" (else woe unto your program)
public class p30a4
{ public static void main (String args[])
{ int inInt = 0;
char inChar;
try
{ System.out.print ("ASCII Char: (// to exit) ");
while (inInt != 13)
{ inInt = System.in.read();
if (inInt==47)
break;
inChar = (char)inInt;
if ((inInt!=10) && (inInt!=13))
{ System.out.println("ASCII Code: " + inInt);
System.out.println(" ");
System.out.print ("ASCII Char: (// to exit) ");
} // end of if
inInt = 0;
} // end of while
System.out.println("Exiting Program. inInt = "+inInt);
} // end of try
catch (Exception e)
{ System.out.println("Error reading from user"); }
}
}
/* this program uses the System.in.read method to accept a char
from the keyboard, and display its ASCII Code.
Hold key down, and press 01 on the numeric pad.
Try it for 164. Relate this to ASCII Table.
Can you 'crash' this program? Cause an error to occur?
How?
Explain why / why not?
What happens when is pressed (null input)?
Understand that if a character is not = 10 AND not = 13
will allow any characters except 10 and 13 to pass through.
It must be true for characters to pass through.
Either a 10 or 13 violates the requirement that the char must
be not a 10 and not a 13.
Assignment: Comment every line of this program.
Download this. Comment out each statement. Note errors and
output. Learn this program by taking it apart and putting it
back together.
end of listin
*/