Computer Applications
Write a program in Java to accept a String from the user. Pass the String to a method Change(String str) which displays the first character of each word after changing the case (lower to upper and vice versa).
Sample Input: Delhi public school
Sample Output:
d
P
S
Answer
import java.util.Scanner;
public class KboatStringChange
{
public void change(String str) {
String t = " " + str;
int len = t.length();
for (int i = 0; i < len - 1; i++) {
if (t.charAt(i) == ' ') {
char ch = t.charAt(i+1);
if (Character.isUpperCase(ch))
ch = Character.toLowerCase(ch);
else if (Character.isLowerCase(ch))
ch = Character.toUpperCase(ch);
System.out.println(ch);
}
}
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a string: ");
String s = in.nextLine();
KboatStringChange obj = new KboatStringChange();
obj.change(s);
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Write a program in Java to accept the name of an employee and his/her annual income. Pass the name and the annual income to a method Tax(String name, int income) which displays the name of the employee and the income tax as per the given tariff:
Annual Income Income Tax Up to ₹2,50,000 No tax ₹2,50,001 to ₹5,00,000 10% of the income exceeding ₹2,50,000 ₹5,00,001 to ₹10,00,000 ₹30,000 + 20% of the amount exceeding ₹5,00,000 ₹10,00,001 and above ₹50,000 + 30% of the amount exceeding ₹10,00,000 Write a program in Java to accept a String from the user. Pass the String to a method Display(String str) which displays the consonants present in the String.
Sample Input: computer
Sample Output:
c
m
p
t
rWrite a program in Java to accept a String from the user. Pass the String to a method First(String str) which displays the first character of each word.
Sample Input : Understanding Computer Applications
Sample Output:
U
C
AWrite a program using a method Palin( ), to check whether a string is a Palindrome or not. A Palindrome is a string that reads the same from the left to right and vice versa.
Sample Input: MADAM, ARORA, ABBA, etc.