P2Cart Logo
Write a program by using scanner class to input a sentence.

This Java program takes a sentence as input, finds the longest word, and displays the word along with its number of characters.

Read more
Write a program by using scanner class to input a sentence. Display the longest word along with number of characters.
Sample Input: We are learning scanner class in Java
Sample Output: The longest word: learning Number of characters: 8

Read Answer
Write a program to accept a sentence in a mixed case.

This Java program accepts a sentence, counts the vowels in each word, and prints the words along with their vowel frequencies.

Read more
Write a program to accept a sentence in a mixed case. Find the frequency of vowels in each word and print the words along with their frequencies in separate lines.
Sample Input: We are learning scanner class
Sample Output: Word                 Frequency
                             We                            1
                             Are                           2
                             Learning                   3
                             Scanner                    2
                             Class                         1

Read Answer
In a competitive examination, a set of 'N' number of questions results in True or 'False'. Write a program by using scanner class to accept the answers.

This Java program accepts a set of 'True' or 'False' answers for a set of questions and displays the frequency of each.

Read more

In a competitive examination, a set of 'N' number of questions results in True or 'False'. Write a program by using the scanner class to accept the answers. Print the frequency of 'True' and 'False'.

Read Answer
Write a menu-driven program to accept a number by using the scanner class. Perform the following tasks.

This Java program provides a menu-driven interface that allows the user to check if a number is a Buzz number and display all the factors of the number excluding itself.

Read more
    Write a menu-driven program to accept a number by using the scanner class. Perform the following tasks.
a)      Check and print whether the number is a 'Buzz number or not. A number is said to be a 'Buzz' number if it is divisible by 7 and it contains the last digits 7.
b)      Display all the factors of the number including 1 and excluding the number itself.

Read Answer
Write a program (using scanner class) to generate a pattern of a token in the form of a triangle or in the form of an inverted triangle depending upon user’s choice.

This Java program generates either a triangle or inverted triangle pattern of a token (*) based on the user's choice using the Scanner class.

Read more
Write a program (using scanner class) to generate a pattern of a token in the form of a triangle or the form of an inverted triangle depending upon the user’s choice.
Sample Input: Enter your choice 1                   Enter your choice 2
Sample Output: *                                                      * * * * *
                            * *                                                    * * * *
                            * * *                                                 * * *
                            * * * *                                              * *
                            * * * * *                                           *

Read Answer
Write a program to accept a set of 50 integers. Find and print the greatest and the smallest numbers by using scanner class method.

This Java program uses the Scanner class to accept 50 integers, then finds and prints the greatest and smallest numbers from the input.

Read more

Write a program to accept a set of 50 integers. Find and print the greatest and the smallest numbers by using the scanner class method.

Read Answer
Write a program (Using scanner class) to input a line and display only numeric tokens.

This Java program extracts and displays only the numeric tokens from a given line of text using the Scanner class.

Read more
Write a program (Using scanner class) to input a line and display only numeric tokens.
Sample Input: 26 January 1950 is celebrated as Republic Day
Sample Output: 26  1950

Read Answer
Using the scanner class, write a program to input 10 important cities with their STD code in two different single-dimensional arrays.

This Java program uses the Scanner class to input 10 cities and their STD codes and displays only those cities that start with a vowel along with their corresponding STD codes.

Read more
Using the scanner class, write a program to input 10 important cities with their STD code in two different single-dimensional arrays. The program displays only those that begin with a vowel with their corresponding STD code.
Sample Input: Enter city and STD code one by one
New Delhi
011
Asansol
0341
Indore
0731
…………..
…………..
Sample Output: Asansol          0341
Indore             0731
……….….          …………..
……….….          …………..

Read Answer
Write a program (Using scanner class) to enter a token/word in a mixed case and display the new token after deleting all the vowels.

This Java program removes all vowels from a mixed-case word and displays the new token using the Scanner class.

Read more
Write a program (Using scanner class) to enter a token/word in a mixed case and display the new token after deleting all the vowels.
Sample Input: Computer
Sample Output: Cmptr

Read Answer
Using the scanner class, write a program to input a line through the console.

This Java program counts and displays the total number of uppercase and lowercase characters in a given line of text using the Scanner class.

Read more
Using the scanner class, write a program to input a line through the console. The program counts and displays the total number of uppercase and lowercase characters present in the String.
Sample Input:    Understanding Computer Application with BlueJ
   Sample Output: No. of lowercase characters = 37
                                No. of uppercase characters = 5

Read Answer
Write a program (using scanner class) to input any given token word to calculate the total number of characters and vowels present in the token.

This Java program calculates the number of characters and vowels in a token and displays the reversed token using the Scanner class.

Read more
Write a program (using scanner class) to input any given token word to calculate the total number of characters and vowels present in the token. The program also displays the reverse token.
Sample Input: SNOWY
Sample Output:
Number of vowels: 01
Number of character: 05
Reversed token: YWONS 
Read Answer
Write a program (Using scanner class) to store 10 different words (in lower case) in a single-dimensional array.

This Java program inputs 10 lowercase words, checks which words start and end with a vowel, and displays those words.

Read more
Write a program (Using scanner class) to store 10 different words (in lower case) in a single-dimensional array. Display all such tokens that begin and end with a vowel.
Sample Input: Enter 10 words in lowercase
                         Umbrella
                         Table
                         Computer
                         Agenda
                         …………
                         …………
Sample Output: umbrella
                            Agenda
                            …………
                            …………
Read Answer
Using the scanner class, write a program to display the sum of even numbers and odd numbers separately from a set of numbers entered by the user.

This Java program calculates and displays the sum of even and odd numbers separately from a set of user inputs, terminating when a non-numeric character is entered.

Read more

Using the scanner class, write a program to display the sum of even numbers and odd numbers separately from a set of numbers entered by the user. The program terminates when the user enters any non-numeric character.

Read Answer
G.C.D. defined as the Greatest Common Divisor between the two numbers is calculated by the continued divisor method. i.e. Divide the larger number by the smaller, the remainder then divides the previous divisor.

This Java program calculates the Greatest Common Divisor (GCD) of two numbers using the continued divisor method.

Read more
G.C.D. defined as the Greatest Common Divisor between the two numbers is calculated by the continued divisor method. i.e. Divide the larger number by the smaller, the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The last divisor gives the GCD. Write a program to input two numbers and display the Greatest Common Divisor by using the scanner class.
Sample Input: Enter two numbers
                              45       85
Sample Output: GCD of two numbers is 5

Read Answer
Using the scanner class, write a program to find and display the sum of any ten numbers entered by the user from the console.

This Java program calculates and displays the sum of ten numbers entered by the user using the Scanner class.

Read more

Using the scanner class, write a program to find and display the sum of any ten numbers entered by the user from the console.

Read Answer
Write a program (using scanner class) to generate a pattern of a token/word in the form of a triangle or in the form of an inverted triangle depending upon user’s choice.

This Java program generates a triangle or inverted triangle pattern from a word based on user input.

Read more
Write a program (using scanner class) to generate a pattern of a token/word in the form of a triangle or in the form of an inverted triangle depending upon user’s choice.
Sample Input: Enter a word as a Token     CLASS
                          Enter your choice 1
                          Enter your choice 2
Sample Output: C  L  A  S  S
C                         C  L  A  S  S
C  L                     C  L  A  S
C  L  A                C  L  A
C  L  A  S            C  L
C  L  A  S  S        C

Read Answer
Using the scanner class, write a program to enter the string through a console and replace the token RED with GREEN without using the built-in function.

This Java program replaces the token "RED" with "GREEN" in a string by manually processing the string without using built-in functions like replace().

Read more
Consider a String as:
RED BOTTLE IS IN RED BAG ON RED CARPET
Using the scanner class, write a program to enter the string through a console and replace the token RED with GREEN without using the built-in function. The new string is displayed as:

GREEN BOTTLE IS IN GREEN BAG ON GREEN CARPET
Read Answer
Write a program to enter two tokens in mixed case.

This Java program compares two tokens entered by the user and arranges them alphabetically based on their ASCII values, ignoring case.

Read more
Write a program to enter two tokens in mixed case. The user compares the strings and wants to arrange them alphabetically. [Hint: Use scanner class]. If the ASCII value of the first character of the token is less than the second, then the first token is smaller and vice-versa. Two strings are said to be equal if their ASCII value is the same.
Sample Input: Computer
                          Science
Sample Output: Computer, Science

Read Answer
A computer typist has the habit of deleting the middle token ‘Kumar’ while entering the names containing three words/tokens.

This Java program removes the middle token "Kumar" from a three-word name and displays the new name.

Read more
A computer typist has the habit of deleting the middle token ‘Kumar’ while entering the names containing three words/tokens. Write a program (using scanner class) to enter the names with three words and display the new name after deleting the middle token ‘Kumar’.
Sample Input: Rajesh Kumar Agarwal
Sample Output: Rajesh Agarwal

Read Answer
Consider the String in lowercase as: the black cat ate the rat in the small house

This Java program reads a string, splits it into words, and counts the occurrences of the token "the" in the string.

Read more
Consider the String in lowercase as:
the black cat ate the rat in the small house
Using Scanner Class, write a program to enter the line ending with a space and terminating with a full stop (.). Display the frequency of the token ‘the’ in the given String.
Sample Input: the black cat ate the rat in the small house.
Sample Output: The frequency of the token ‘the’ = 3

Read Answer