
CSC 1760 Introduction to Programming
Lesson 7: Elementary Programming
Due Date: 1/30/2009
1. Textbook: Introduction to Java Programming, Brief Version, Seventh Edition,
Author: Y. Daniel Liang, 2009, Prentice Hall
a. Chapter 2
2. Overview
Demonstrate elementary programming skills.
3. Tasks
a. Write a program named CharEscape.java that displays the following,
exactly as show:
Character Escape Sequence Name Unicode Code
\t Tab \u008
\\ Backslash \u005C
\โ Single Quote \u0027
\โ Double Quote \u0022
Note: you will have to use character escape sequences for tab, linefeed,
backslash, single quote, and double quote.
b. Write a program named ShortHand.java that uses short hand operators
such as +=, -=, *=, /=, %=, ++var, var++, --var, var--.
c. Write a program named ToLowercase.java that inputs an uppercase letter
and converts it to a lowercase letter. The character is typed in the source
code as a literal value. Hint: In the ASCII table (see Appendix B in the
textbook), uppercase letters appear before lowercase letters. The offset
between any uppercase letter and its corresponding lowercase letter is the
same. So you can find a lowercase letter from its corresponding uppercase
letter as follows:
int offset = (int)โaโ โ (int)โAโ;
int unicodeForUppercase = (int)uppercase;
int unicodeForLowercase = unicodeForUppercase + offset;
char lowercase = (char)unicodeForLowrecase;
Note how casting is used to get to the value needed.
Note2: You will need to use the following code to input a single character
using Scanner:
Scanner input = new Scanner(System.in);
System.out.print("Enter an uppercase character: ");
char uppercase = input.next().charAt(0);