Computer Science, asked by Anonymous, 1 year ago

write a java program to accept a line of text from the user and create a new word formed out of the first letter of each word in the output in uppercase followed by a full stop.

Answers

Answered by Rajkumarpatel89
13
Example :
INPUT SENTENCE : “This is a cat”
OUTPUT : T.I.A.C.


Solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/** The class Initials takes a sentence/name as input and prints it's initials.
* @author : www.javaforschool.com
* @Program Type : BlueJ Program - Java
*/

import java.io.*;
class Initials
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s;
char x;
int l;
System.out.print("Enter any sentence: ");
s=br.readLine();
s=" "+s; //adding a space infront of the inputted sentence or a name
s=s.toUpperCase(); //converting the sentence into Upper Case (Capital Letters)
l=s.length(); //finding the length of the sentence
System.out.print("Output = ");

for(int i=0;i{
x=s.charAt(i); //taking out one character at a time from the sentence
if(x==' ') //if the character is a space, printing the next Character along with a fullstop
System.out.print(s.charAt(i+1)+".");
}
}
}
Output:
Enter any sentence: Java for school students
Output = J.F.S.S
Answered by anirudhpkk
0

Answer:

class Main {

public static void main(String[] args) {

// create a string

String name = "programiz";

// create two substrings from name

// first substring contains first letter of name

// second substring contains remaining letters

String firstLetter = name.substring(0, 1);

String remainingLetters = name.substring(1, name.length());

// change the first letter to uppercase

firstLetter = firstLetter.toUpperCase();

// join the two substrings

name = firstLetter + remainingLetters;

System.out.println("Name: " + name);

}

}

Explanation:

pls mark me as brilliant

full star pls

Similar questions