Explanation:
User give an input as a sentence. That contains set of words separated by space. We have to print the Capital letters in the given input sentence.Input format:
Enter any sentence:Let Us Code in C Let Us Code in JAVA
Output format:
L U C C L U C J A V AProgram:
import java.util.Scanner;public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter any Sentence");
String ss = s.nextLine();
String[ ] a = ss.split(" ");
String res = "";
for(int i = 0;i<a.length;i++)
{
String str = a[i];
for(int j = 0;j<str.length();j++)
{
int ch = str.charAt(j);
if(ch<=90 && ch>=65)
{
res+ = str.charAt(j)+" ";
}
}
}
System.out.println(res);
}
}
Source Code: download
0 comments:
Post a Comment