×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Find Longest word in a sentence through java Advance Array Examples In Java
Find the highest and the lowest character in a word through java - Java
7633    Arnab De    09/09/2018

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.

softetechnologies
import java.util.*;

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

softetechnologies

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

Find Longest word in a sentence through java Advance Array Examples In Java
softetechnologies
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.
Enter New Comment
Comment History
28/08/2021: CAN ANYONE PLZ HELP ME WITH THIS PROGRAM: Define a class WordOp having the following description: 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 the word. Member functions: WordOp(String s) : parameterized constructor to accept a 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 lowest character.
By: prajjwal [prajjwalpramil@gmail.com]
Sri Sri Ramakrishna Paramahamsa
One cannot be spiritual as long as one has shame, hatred, or fear.
Sri Sri Ramakrishna Paramahamsa
527
50.6
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     41335
01/01/2018     35758
28/06/2017     33755
25/06/2018     32805
02/08/2017     32088
06/07/2017     26587
01/08/2017     26549
15/05/2017     26191
14/07/2017     21521
21/04/2018     20501
softetechnologies