P2Cart Logo
Write a menu-driven program using a method Number ( ) to perform the following tasks:

This Java program allows the user to check if a number is a Buzz number or a Composite number through a menu-driven interface. The user can select an option and enter a number to perform the desired check.

Read more
     Write a menu-driven program using a method Number ( ) to perform the following tasks:
a)      Accept a number from the user and check whether it is a ‘BUZZ’ number or not. A Buzz number is the number which either ends with 7 is or divisible by 7.
b)      Accept a number from the user and check whether it is a composite number or not. A composite number has more than one factor (excluding 1 and the number itself).

Read Answer
Write a class with the name volume using function overloading that computers the volume of a cube, a sphere and a cuboid.

This Java program defines a class Volume with overloaded methods to calculate the volumes of a cube, sphere, and cuboid. The program accepts user input and calculates the corresponding volumes.

Read more
Write a class with the name volume using function overloading that computers the volume of a cube, a sphere and a cuboid.
Formula: Volume of a cube (vc) = s*s*s
                  Volume of a sphere (vs) = 4/3*π*r*r*r
                  Volume of a cuboid (vcd) = l*b*h

Read Answer
Write a program in Java to interchange the value (swap) of the two numbers a and b and display the result after swapping.

This Java program uses overloaded methods to swap integer and float values separately, displaying the result before and after the swap.

Read more
Write a program in Java to interchange the value (swap) of the two numbers a and b and display the result after swapping.
Use overloaded methods display (int, int) and display (float, float) for swapping integer and float type values.
Read Answer
Write a program to find the sum of the given series to n terms by using the function name sum (int).

This Java program calculates the sum of the series (1*2) + (2*3) + (3*4) + ... up to n terms using the function sum(int n) and displays the result.

Read more
Write a program to find the sum of the given series to n terms by using the function name sum (int). Write the main program to display the sum of the series.

S = (1*2) + (2*3) + (3*4) + ……………….. to n terms.
Read Answer
Write a program in Java to accept a word and pass the word to a function named Void display (String a).

This Java program accepts a word and uses a function display to find and display all the vowels (a, e, i, o, u) present in the word.

Read more
Write a program in Java to accept a word and pass the word to a function named Void display (String a). Display all the vowels present in the word.
[Hint: non-return type]
Sample Input: Enter a word
                          Cimputer
The vowels are:  o
                             u
                             e

Read Answer
Write a program to calculate the monthly electricity bill of a consumer according to the units consumed.

This program calculates and displays the monthly electricity bill of a consumer based on units consumed and specified tariff rates. It uses a function cal(int u) to compute the bill and outputs the details in a formatted manner.

Read more
Write a program to calculate the monthly electricity bill of a consumer according to the units consumed. The tariff is given below:

Units Consumed

Charge

Up to 100 units

Rs. 1.25 per unit

For the next 100 units

Rs. 1.50 per unit

More than 200 units

Rs. 1.80 per unit

 Unit consumed = Present reading – Previous reading

Use a function name cal (int u) and print the information in the main function as per the given format:
Consumer No.             Name               Units consumed                      Amount
        xxx                        xxx                        xxx                                      xxx

Read Answer
Write a program in Java to accept two numbers and check whether they are twin prime or not, using function name prime ( ).

This Java program determines if two numbers are twin primes. It uses a function prime(int n) to verify if numbers are prime and checks if the difference between the two numbers is exactly 2.

Read more
Write a program in Java to accept two numbers and check whether they are twin prime or not, using the function name prime ( ). The function returns 1 if the number is prime otherwise returns 0.
Twin Prime numbers are prime numbers whose difference is 2. (11, 13),(17, 19), ………….. are examples of twin prime numbers.

Read Answer
An automorphic number is the number which is contained in the last digit (s) of its square.

This Java program checks if a number is Automorphic using a function digits(int n) to calculate the number of digits. It determines if the original number matches the last digits of its square.

Read more

An automorphic number is the number that is contained in the last digit (s) of its square. Write a program in Java to accept a number and check whether it is an Automorphic number or not, using function name digits (int n) which returns the number of digits present in the number. For example, 25 is an automorphic number, with a square of 625, and 25 is present as the last two digits.

Read Answer
Write a program in Java to accept a number and check whether a number is palindrome or not, using function name reverse (int n) which returns the number after reversing the digits.

This Java program checks if a number is a palindrome using a reverse(int n) function that returns the reversed number. It compares the original number with its reversed form.

Read more
Write a program in Java to accept a number and check whether a number is palindrome or not, using the function name reverse (int n) which returns the number after reversing the digits.
Read Answer
Write a program in Java to accept a number and check whether the number is prime or not using the function name check (int n).

This Java program determines if a number is prime using a function check(int n) that returns 1 for prime and 0 otherwise. The user inputs a number, and the program outputs whether it is prime.

Read more

Write a program in Java to accept a number and check whether the number is prime or not using the function name check (int n). The function returns 1 if the number is prime otherwise 0. 

Read Answer
Write a program by using the scanner class to input principal (P), rate (R) and time (T).

This Java program calculates the compound interest and amount based on user input for principal, rate, and time. The calculation continues until the user enters an alphabet, after which the program terminates.

Read more
Write a program using the scanner class to input principal (P), rate (R), and time (T). Calculate and display the amount and compound interest until the user wants it. The program terminates as soon as an alphabet is entered.
Use the formula: A = P(1 + R/100)T
                                             CIA - P

Read Answer
Mohit (a Nursery student) learns 26 English alphabets (i.e. A to Z) concerning their position, viz. A as 1, B as 2, Y as 25 and Z as 26.

This Java program accepts a word in uppercase, and for each letter, it displays its position in the alphabet, where 'A' is 1, 'B' is 2, and so on.

Read more
Mohit (a Nursery student) learns 26 English alphabets (i.e. A to Z) concerning their position, viz. A as 1, B as 2, Y as 25 and Z as 26.
Write a program to input a word in uppercase and display the position of each alphabet by using the scanner class.
Sample Input: COMPUTER
Sample Output: C                   3
                             O                  15
                             M                  13
                             P                   16
                             U                  21
                             T                   20
                             E                   5
                             R                  18

Read Answer
Write a program (using scanner class) to change 26 to 15, January to August, Republic to Independence and finally print as:

This Java program replaces specific words in a predefined sentence using the replace() method and displays the modified sentence.

Read more
Consider the following statement:
"26 January is celebrated as the Republic Day of India"
Write a program (using scanner class) to change 26 to 15, January to August, Republic to Independence and finally print as:
"15 August is celebrated as the Independence Day of India"

Read Answer
Write a program to input a string by using scanner class. Display the new string which is formed by the first character of each string.

This Java program accepts a string input and forms a new string by concatenating the first character of each word in the input string.

Read more
Write a program to input a string by using the scanner class. Display the new string which is formed by the first character of each string.
Sample Input: Automated Teller Machine
Sample Output: ATM

Read Answer
Using scanner class, write a program to input a string and display all the tokens of the string which begin with a capital letter and end with a small letter.

This Java program takes a string input, identifies the words that begin with a capital letter and end with a small letter, and prints those words.

Read more
Using scanner class, write a program to input a string and display all the tokens of the string which begin with a capital letter and end with a small letter.
Sample Input: The capital of India is New Delhi
Sample Output: The India New Delhi

Read Answer
Write a program by using the scanner class to enter the string and display the new string after removing the repeating token 'THE'. The new string is:

This Java program accepts a string from the user and removes all occurrences of the token "THE" except the first one. The new string is then displayed.

Read more
Consider a String as:
THE COLD WATER AND THE HOT WATER glasses ARE KEPT ON THE TABLE Write a program by using the scanner class to enter the string and display the new string after removing the repeating token 'THE'. The new string is:
COLD WATER AND HOT WATER glasses ARE KEPT ON TABLE

Read Answer
Using the scanner class, write a program to accept a sentence and display only Palindrome words.

This Java program accepts a sentence, identifies the palindrome words, and displays them.

Read more
Using the scanner class, write a program to accept a sentence and display only Palindrome words. A word is 'Palindrome' if it appears to be the same after reversing its characters.
Sample Input: MADAM ARORA IS OUR ENGLISH TEACHER
  Sample Output: MADAM
                              ARORA

Read Answer
Write a program to generate random numbers between 1 to N by using scanner class, taking N from the console.

This Java program accepts a set of positive and negative numbers, then prints the negative numbers first while keeping their original order, followed by the positive numbers.

Read more
Write a program to generate random numbers between 1 to N by using the scanner class, taking N from the console.
Read Answer
Write a program by using a scanner class to accept a set of positive and negative numbers randomly.

This Java program accepts a set of positive and negative numbers, then prints the negative numbers first while keeping their original order, followed by the positive numbers.

Read more
Write a program by using a scanner class to accept a set of positive and negative numbers randomly. Print all the negative numbers before the positive numbers without changing the order of the numbers.
Sample Input: 1, 5, -2, 6, 3, 5, 8, 4, 9, 12
Sample Output: -2, -3, -5, -4, 1, 5, 6, 8, 9, 12

Read Answer
Print each word of the sentence along with the sum of ASCII codes of its character.

This Java program takes a sentence as input, calculates the sum of ASCII values of the characters for each word in the sentence, and displays the word along with the corresponding sum.

Read more

Write a program by using the scanner class to input a sentence. Print each word of the sentence along with the sum of ASCII codes of its character.

Read Answer