Share this post on:

Here in this Program we will take a string from which we will get the smallest and largest character from that string. we will find Largest and smallest character from a string in Java.

public class Practice
{
static char largest(String a, int n)
{
char max=’A’;
for(int i=0;i max )
max=a.charAt(i);
return max;
}

static char smallest(String a,int n)
{
char min=’Z’;
for(int i=0;i<n-1;i++)
if(a.charAt(i)<min)
min=a.charAt(i);

return min;
}

public static void main(String[] args)
{
String a = “ArzaTechs”;
int size=a.length();

System.out.println(“Largest Character from String is: “+largest(a,size));
System.out.println(“Smallest Character from String is: “+smallest(a,size));

}

}

Output:

Largest Character from String is: z
Smallest Character from String is: A

Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

Leave a Comment

Your email address will not be published. Required fields are marked *