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
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


Related Questions
Consider a String:
THE COLD WATER AND THE HOT WATER GLASSES ARE KEPT ON THE TABLEWrite a program by using scanner class to enter the string and display the new string after removing repeating token 'THE'. The new string is:
COLD WATER AND HOT WATER GLASSES ARE KEPT ON TABLE
Using scanner class, write a program to input a string and display all the tokens of the string which begin with a capital letter and end with a small letter.
Sample Input: The capital of India is New Delhi
Sample Output: The India New DelhiConsider the following statement:
"26 January is celebrated as the Republic Day of India"Write a program (using scanner class) to change 26 to 15; January to August; Republic to Independence and finally print as:
"15 August is celebrated as the Independence Day of India"
Write a program by using scanner class to input principal (P), rate (R) and time (T). Calculate and display the amount and compound interest. The program terminates as soon as an alphabet is entered.
Use the formula:
A = P(1 + (R / 100))T
CI = A - P