KnowledgeBoat Logo

Computer Applications

Write a program in Java to input a character. Display next 5 characters.

Java

Java Library Classes

97 Likes

Answer

import java.util.Scanner;

public class KboatFiveChars
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a character: ");
        char ch = in.next().charAt(0);
        
        System.out.println("Next 5 characters from " 
            + ch + " are:");
            
        for (int i = 1; i <= 5; i++) {
            System.out.println(++ch);
        }
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program in Java to input a character. Display next 5 characters.BlueJ output of Write a program in Java to input a character. Display next 5 characters.

Answered By

38 Likes


Related Questions