Find the highest and the lowest character in a word through java
09-09-2018    623 times
highest lowest character java

Data members/instance variables:

str : to store a word

max : to store the highest alphabetical character present in the word

min : to store the lowest alphabetical character present in theword

Member functions:

WordOp() : default constructor

Void input() : to accept the word in UPPERCASE

Void calcMaxMin() : to find the highest and the lowest character present in the word. Void display() : to display the word along with the highest and the lowestcharacter

Example: If word is "TWEAK" then

Highest Character =W

Lowest Character = A

Read a word using next() method of Scanner class. Now extract the individual character from the word using charAt() method and store into a charcter variable called ch. Now compare the ch to max or min and store the highest character in max variable and lowest character in min variable. Now print the variable.

Tutorial at home
import java.util.*;

public class WordOp
    private String str;
    private char max,min;
    public WordOp()
    void input()
        Scanner sc=new Scanner(;
        System.out.println("Enter a String in a upper case : ");;
    void calcMaxMin()
        char ch;
        for(int i=0;i<str.length();i++)
    void display()
        System.out.println("Highest Character = " + max); 
        System.out.println("Lowest Character = " + min);
    public static void main(String []args)
        WordOp op=new WordOp();

Tutorial at home

Enter a String in a upper case :
Highest Character = W
Lowest Character = A

    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post