SLExp 6
SLExp 6
import java.util.*;
class Capital
{
public static void main(String args[])
{
String str, upperCase;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string:- ");
str = sc.nextLine();
upperCase = str.toUpperCase();
System.out.println("String in uppercase:- " + upperCase);
sc.close();
}
}
Output:-
Enter a string:-
hello
String in uppercase:-
HELLO
import java.util.*;
class Small
{
public static void main(String args[])
{
String str, lowerCase;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string:- ");
str = sc.nextLine();
lowerCase = str.toLowerCase();
System.out.println("String in lowercase:- " + lowerCase);
sc.close();
}
}
Output:-
Enter a string:-
HELLO
String in lowercase:-
hello
//Write a program to find uppercase, lowercase, digits, blankspaces and special symbols in the user
entered string.
import java.util.*;
public class Demo {
String a;
int u , l , d , bs , sp ;
Scanner sc = new Scanner(System.in);
void accept()
{
System.out.println("Enter a string:");
a = sc.nextLine();
}
void calculate()
{
for (int i = 0; i < a.length(); i++)
{
char ch = a.charAt(i);
if (ch >= 'A' && ch <= 'Z')
{
u++;
}
else if (ch >= 'a' && ch <= 'z')
{
l++;
}
else if (ch >= '0' && ch <= '9')
{
d++;
}
else if (ch == ' ')
{
bs++;
}
else
{
sp++;
}
}
}
void display()
{
System.out.println("Number of uppercase letters: " + u);
System.out.println("Number of lowercase letters: " + l);
System.out.println("Number of blankspaces: " + bs);
System.out.println("Number of digits: " + d);
System.out.println("Number of special symbols: " + sp);
}