P2Cart Logo
Write a program in Java to accept a String from the user. Pass the String to a function Display (String str) which displays the consonants present in the String

This Java program takes a string input from the user and displays all the consonants present in that string, one per line. The program ensures case-insensitivity and skips vowels.

Read more
Write a program in Java to accept a String from the user. Pass the String to a function Display (String str) which displays the consonants present in the String
Sample Input : computer
Sample Output: c
                            m
                            p
                            t
                            r
Read Answer
Write a class with the name Perimeter using function overloading that computes the perimeter of a square, a rectangle and a circle.

This Java program uses function overloading to calculate the perimeter of a square, rectangle, and circle. It accepts user input for the relevant dimensions and computes the perimeter for each shape accordingly.

Read more
Write a class with the name Perimeter using function overloading that computes the perimeter of a square, a rectangle and a circle.
Formula: Perimeter of a square = 4*s
             Perimeter of a rectangle = 2*(1+b)
                   Perimeter of a circle = 2*π*r

Read Answer
Write a class with the name Area using function overloading that computes the area of a parallelogram, a rhombus and a trapezium.

This Java program uses function overloading to calculate the area of a parallelogram, rhombus, and trapezium. The program takes user input for the relevant dimensions of each shape and computes the area accordingly.

Read more
Write a class with the name Area using function overloading that computes the area of a parallelogram, a rhombus and a trapezium.
Formula: Area of a parallelogram (pg) = b*h
Area of a rhombus (rh) = ½ *d1*d2 (where, d1 and d2 are the diagonals)
Area of a trapezium (tr) = ½ (a + b)*h (where, a and b are the parallel sides, h = perpendicular distance between the parallel sides)

Read Answer
Write a program in Java using the method Discount( ), to calculate a single discount or a successive discount.

This Java program calculates single or successive discounts on the printed price of an article using overloaded methods. It computes the final price based on user input and displays the amount to be paid.

Read more
Write a program in Java using the method Discount( ), to calculate a single discount or a successive discount. Use overload methods Discount (int), Discount (int, int) and Discount (int, int, int) to calculate the single discount and successive discount respectively. Calculate and display the amount to be paid by the customer after getting discounts on the printed price of an article.
Sample Input: Printed Price: Rs. 12000
                                      Successive discounts = 10%, 8%
                                                                         = Rs. (12000-1200)
                                                                         = Rs. (10800-864)
                                          Amount to be paid = Rs.9936

Read Answer
A Palindrome is a string that reads the same from the left to right and vice versa.

This Java program uses a method to determine if a string is a palindrome. It checks whether the string reads the same forwards and backwards and provides the result.

Read more
Write a program using the method Palin ( ), to check whether a string is a Palindrome or not. A Palindrome is a string that reads the same from the left to right and vice versa.

Sample Input: MADAM, ARORA, ABBA etc.
Read Answer
Write a program using a function called area ( ) to compute the area of a

This Java program computes the area of a circle, square, or rectangle based on the user's choice. It uses functions to calculate the areas and displays a menu for easy selection.

Read more
    Write a program using a function called area ( ) to compute the area of a
a)      circle (π*r²) where π = 3.14
b)      square (side*side)
c)      rectangle (length*breadth)
Display the menu to output the area as per User's choice.

Read Answer
Define a function int prime (int x) to check whether a number is prime or not. It returns 1 if the number is prime, O otherwise.

This Java program accepts 10 integers in an array, uses a custom function to determine whether each number is prime, and prints all prime numbers in the array.

Read more

Write a program in Java to accept 10 numbers in an array. Define a function int prime (int x) to check whether a number is prime or not. It returns 1 if the number is prime, O otherwise. Use the function to check and print all the prime numbers of the array.

Read Answer
Write a program in Java to accept 10 numbers in a Single Dimensional Array Pass the array to a function swap (int a[]) to interchange the numbers in such a way that a[0] is interchanged with 3a[1], a[2] with a[3] and so on.

This Java program accepts 10 integers in an array, interchanges numbers using a custom swapping logic (a[0] with 3 * a[1], a[2] with a[3], etc.), and prints the updated array.

Read more

Write a program in Java to accept 10 numbers in a Single Dimensional Array Pass the array to a function swap (int a[]) to interchange the numbers in such a way that a[0] is interchanged with 3a[1], a[2] with a[3] and so on. Finally print all the numbers of the array.

Read Answer
Write a program in Java to input a string using upper and lower case characters. Pass the string to a function lower (String x) to print only lower case letters.

This program extracts and prints only the lower case letters from a mixed-case string provided by the user.

Read more

Write a program in Java to input a string using upper and lower case characters. Pass the string to a function lower (String x) to print only lower case letters.

Read Answer
If two letters are consecutive in any position the function prints "It is a magic string" otherwise prints "It is not a magic string".

This Java program checks if a word contains consecutive letters in the alphabet using the magic(String x) function.

Read more

Write a program in Java to accept a word. Pass it to a function magic (string x) The function checks the string for the presence of consecutive letters. If two letters are consecutive in any position the function prints "It is a magic string" otherwise prints "It is not a magic string".

Read Answer
Write a Java program to accept a string. Pass it to a function freq (String x). the function finds and prints the frequency of each vowel.

This Java program accepts a string and calculates the frequency of each vowel (A, E, I, O, U) in the string using the freq() function.

Read more

Write a Java program to accept a string. Pass it to a function freq (String x). the function finds and prints the frequency of each vowel.

Read Answer
Write a function fact (int n) to find the factorial of a number n. include a main class to find the value of S where:

This Java program computes the value of � S based on the formula � = � ! � ( � − � ) ! S= m(n−m)! n! ​ , where the factorial of a number is calculated using the fact() function.

Read more
Write a function fact (int n) to find the factorial of a number n. include a main class to find the value of S where:

S = n! / m(n - m)!
Read Answer
Use a function int Armstrong(int n) to receive the number. The function returns 1 if the number is Armstrong otherwise 0.

This Java program checks if a given number is an Armstrong number or not. It uses a function Armstrong(int n) to perform the check and return 1 if the number is Armstrong, otherwise 0.

Read more

Write a Java program to input a number. Use a function int Armstrong(int n) to receive the number. The function returns 1 if the number is Armstrong otherwise 0.

Read Answer
Use a function daysofweek(int dysno) to accept the day number from the main class.

This Java program accepts a day number (between 1 and 7) from the user and uses a switch-case statement to print the corresponding day of the week.

Read more

Write a program in Java to input the day number. Use a function daysofweek(int dysno) to accept the day number from the main class. The function uses a switch-case statement to print the corresponding day of the week.

Read Answer
Write a Java program to input the sides of a triangle.

This Java program accepts the lengths of the three sides of a triangle from the user and checks whether the triangle is equilateral, isosceles, or scalene based on the values of the sides.

Read more

Write a Java program to input the sides of a triangle. Pass the sides to a function decide (int x, int y, int z) which checks and prints whether the triangle is equilateral, isosceles or scalene.

Read Answer
Write a program in Java to input 10 numbers. Use a function to find and print the cube of each number.

This Java program accepts 10 numbers from the user and then uses the printCube() function to calculate and print the cube of each number.

Read more

Write a program in Java to input 10 numbers. Use a function to find and print the cube of each number.

Read Answer
The function will find whether the given element is the list or not. It returns true if found, false otherwise i.e. Boolean return type.

This Java program accepts 10 numbers, and a search number, then checks if the search number exists in the array. It uses the search() function which returns a boolean value (true if the number is found, false otherwise).

Read more
Write a program in Java to accept 10 numbers in Single Dimensional Array. Pass the array to a function search (int m[], int ns). The function will find whether the given element is in the list or not. It returns true if found, false otherwise i.e. Boolean return type.
Read Answer
Write a program in Java to accept 10 numbers in S.D.A and pass all array to a function.

This Java program accepts 10 numbers, performs binary search to find a specific number, and displays whether the number is present or not in the sorted array.

Read more
Write a program in Java to accept 10 numbers in S.D.A and pass all array to a function. Enter a number and check whether it is present or not by creating a function and its object with three parameters (int m[], int b, int ns) using Binary Search technique, if the number is present then display the message “Number is present” otherwise “Number is not present”. 
Read Answer
Arrange all the numbers in ascending order.

This Java program sorts a set of 10 numbers entered by the user in ascending order. It uses a sort() method to implement the sorting logic and then displays the sorted numbers.

Read more

Write a program in Java to accept 10 numbers in Single Dimensional Array. Pass the array to the function sort (int m[]). Arrange all the numbers in ascending order.

Read Answer
Design a class to overload a function num_cal ( ) as follows:

This program demonstrates function overloading in Java by implementing multiple versions of the num_cal() method that perform different tasks based on the input arguments: computing squares/cubes, computing sums/products of integers, and comparing two strings.

Read more
     Design a class to overload a function num_cal ( ) as follows:
a)      Void num_cal (int num, char ch) with one integer argument and one character argument. It computers the square of an integer if choice ch is ‘s’ otherwise, it computers its cube.
b)      Void num_cal (int a, int b, char ch) with two integer arguments and one character argument. It computers the product of integer arguments if ch is ‘p’ else adds the integers.
c)      Void num_cal (String str 1, String str2) with two String arguments prints whether the two String are equal or not.

Read Answer