0% found this document useful (0 votes)
11 views3 pages

SLExp 6

Uploaded by

2403rjgyy6soham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

SLExp 6

Uploaded by

2403rjgyy6soham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

//Write a program to convert the given string into Uppercase and Lowercase.

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);
}

public static void main(String args[])


{
Demo d = new Demo();
d.accept();
d.calculate();
d.display();
}
}
Output:-
Enter a string:
The 2 quick brown Fox Jumps, Over the 3 lazy Dog.
Number of uppercase letters: 5
Number of lowercase letters: 30
Number of blankspaces: 10
Number of digits: 2
Number of special symbols: 2

You might also like