SIGNMENT. START ASAP For this assignment you have four programming problems to s
ID: 3599575 • Letter: S
Question
SIGNMENT. START ASAP For this assignment you have four programming problems to solve. This assignment emphasizes working with data types. Make sure to answer all the questions correctly to get the full mark. 1. [10 marks] Write a Java program that converts an uppercase letter to a lowercase letter. The program prompts the user to enter an uppercase letter and then it displays the corresponding lowercase of that letter. [Hint: In the ASCII table (see Appendix B), uppercase letters appear before lowercase letters. The offset between any uppercase letter and its corresponding lowercase letter is the same.] Test Data: Please enter the uppercase letter: K Expected Output: The lowercase letter of K is kExplanation / Answer
import java.util.Scanner;
public class UpperToLower {
public static void main(String[] args) {
char upper;
Scanner sc = new Scanner(System.in);
System.out.print("Please enter the uppercase letter: ");
upper = sc.nextLine().charAt(0);
char lower = (char)('a' + (upper - 'A'));
System.out.println("The lowercase letter for " + upper + " is " + lower);
sc.close();
}
}
Sample execution
Please enter the uppercase letter: K
The lowercase letter for K is k
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.