Computer Applications

Write a program to input a string by using scanner class. Display the new string which is formed by the first character of each string.

Sample Input: Automated Teller Machine
Sample Output: ATM

Java

Input in Java

2 Likes

Answer

import java.util.Scanner;

public class KboatInitials
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a sentence ending with a space & terminating with (.):");
        while (in.hasNext()) {
            String word = in.next();
            if (word.equals("."))
                break;
            System.out.print(word.charAt(0));
        }
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input a string by using scanner class. Display the new string which is formed by the first character of each string. Sample Input: Automated Teller Machine Sample Output: ATMBlueJ output of Write a program to input a string by using scanner class. Display the new string which is formed by the first character of each string. Sample Input: Automated Teller Machine Sample Output: ATM

Answered By

2 Likes


Related Questions