186k views
1 vote
Declare a character variable letterStart. Write a statement to read a letter from the user into letterStart, followed by statements that output that letter and the next letter in the alphabet. End with a newline. Note: A letter is stored as its ASCII number, so adding 1 yields the next letter. Sample output assuming the user enters 'd': De Hint -- Replace the

1 Answer

1 vote
  1. Answer: import java.util.Scanner; public class CharTestt { public static void main(String[] args) { System.out.println("Please enter a character "); Scanner input = new Scanner(System.in); char letterStart = input.next().charAt(0); char thenextChar = (char)(letterStart+1); System.out.print(letterStart); System.out.println(thenextChar); } } Explanation: Import Scanner Class Prompt user to enter a character Read and save user's input in a variable char letterStart = input.next().charAt(0); Knowing that the next character using ASCII is +1, create a new character variable and add 1 print the character entered and the new character all on same line without spaces
User Sujivasagam
by
8.4k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.