P2Cart Logo
Write a menu-driven class that accepts a number from the user and checks whether it is a Palindrome or a Perfect number.

This Java program allows users to check if a given number is a Palindrome or a Perfect number through a menu-driven interface, showcasing basic control structures and methods.

Read more
            Write a menu-driven class that accepts a number from the user and checks whether it is a Palindrome or a Perfect number.
        i.            Palindrome number : (A number from the user and check read in reverse order is same as in the right order).Example: 11, 101, 151, Atc.
      ii.            Perfect number: (A number is called Perfect if it is equal to the sum of its factors other than the number itself). Example: 6 = 1 + 2 + 3
Read Answer
Write a program to display the given pattern: 1 2 3 4 5, 2 2 3 4 5, 3 3 3 4 5, 4 4 4 4 5, 5 5 5 5 5

This Java program generates a pattern where each row begins with incrementing integers followed by repetitions of the current row number, showcasing a combination of columns based on the current row.

Read more
Write a program to display the given pattern:

1   2   3   4   5

2   2   3   4   5

3   3   3   4   5

4   4   4   4   5

5   5   5   5   5

Read Answer
Write a program in Java to display the given pattern 1 2 3 4 5 6 7, 1 2 3 4 5, 1 2 3, 1

This Java program generates a decreasing number pattern where the first row starts with 7 numbers and each subsequent row reduces by 2 numbers until only 1 number is printed in the final row.

Read more
Write a program in Java to display the given pattern

1   2   3   4   5   6   7

1   2   3   4   5

1   2   3

1

Read Answer
Write a program to display the given pattern: 1, 2 3, 4 5 6 ,7 8 9 10 ,11 12 13 14 15

This Java program displays a number pattern in which the numbers start from 1 and are arranged in a triangular fashion, with each row containing one more number than the previous row. The numbers are printed sequentially.

Read more
Write a program to display the given pattern:

1

2   3

4   5   6

7   8   9   10

11   12   13   14   15

Read Answer
Write a program in Java to find the sum of the given series S = 1/2 - 2/3 - 3/4 - ……… - 10/11

This program calculates the sum of the series � = 1 2 − 2 3 − 3 4 − ⋯ − 10 11 S= 2 1 ​ − 3 2 ​ − 4 3 ​ −⋯− 11 10 ​ using a loop structure in Java. The result is displayed after calculating the total sum of the terms.

Read more
Write a program in Java to find the sum of the given series

S = 1/2 - 2/3 - 3/4 - ……… - 10/11

Read Answer
Write a program to find the sum of series, taking the value of ‘a’ and ‘n’ from the user. S = a+1/2 + a+3/4 + a+5/3 + ………… + to n

Here is a Java program that calculates the sum of the series � = � + 1 2 + � + 3 4 + � + 5 3 + … S=a+ 2 1 ​ +a+ 4 3 ​ +a+ 3 5 ​ +… up to n terms, where a and n are provided by the user:

Read more
Write a program to find the sum of the series, taking the values of ‘a’ and ‘n’ from the user.

S = a+1/2 + a+3/4 + a+5/3 + ……… + to n

Read Answer
Write a program to find the sum of series, taking the value of ‘a’ and ‘n’ from the user. S = a/1 + a/2 + a/3 + a/4 + ……… + a/n

This program calculates the sum of the series � = � 1 + � 2 + � 3 + … + � � S= 1 a ​ + 2 a ​ + 3 a ​ +…+ n a ​ , where 'a' and 'n' are provided by the user as input. It uses a loop to compute each term in the series and outputs the total sum.

Read more
Write a program to find the sum of the series, taking the values of ‘a’ and ‘n’ from the user.

S = a/1 + a/2 + a/3 + a/4 + ………………………………… + a/n

Read Answer
Write a program In Java to find the sum of the series S = 1 + (1*2) + (1*2*3) + …………… + 10 terms

This Java program calculates the sum of the series � = 1 + ( 1 × 2 ) + ( 1 × 2 × 3 ) + ⋯ + 10 S=1+(1×2)+(1×2×3)+⋯+10 terms. It uses nested loops to compute the product of numbers for each term and then adds it to the running sum.

Read more
Write a program In Java to find the sum of the series

S = 1 + (1*2) + (1*2*3) + …………… + 10 terms

Read Answer
Write a program in Java to find the sum of the series S = 1+ 1/2 +1/3 + ……… +1/10

This Java program calculates and displays the sum of the series � = 1 + 1 2 + 1 3 + . . . + 1 10 S=1+ 2 1 ​ + 3 1 ​ +...+ 10 1 ​ . It uses a loop to compute the sum of the reciprocal values of the first ten natural numbers.

Read more
Write a program in Java to find the sum of the series

S = 1+ 1/2 +1/3 + ……… +1/10

Read Answer
Write a program in Java to display the first 10 numbers of the Fibonacci series 0, 1, 1, 2, 3, ………

This Java program generates and displays the first 10 numbers of the Fibonacci series: 0, 1, 1, 2, 3, and so forth. It uses a simple loop to calculate each term based on the sum of the previous two terms.

Read more
Write a program in Java to display the first 10 numbers of the Fibonacci series

0, 1, 1, 2, 3, ………

Read Answer
Write a program in Java to display the first eight numbers of the series 1, 11, 111, 1111, 11111,...........

This Java program generates and displays the first eight numbers of the series: 1, 11, 111, 1111, 11111, and so on. It uses a StringBuilder to construct each number iteratively and prints them to the console.

Read more
Write a program in Java to display the first eight numbers of the series

1, 11, 111, 1111, 11111, ………

Read Answer
In a toss game, you want to know the number of times of getting ‘Head’ and ‘Tail’.

This Java program simulates tossing a coin 20 times, tracking the number of times "Head" (1) and "Tail" (0) appear. It uses random number generation to simulate the tosses and displays the counts after completion.

Read more
In a toss game, you want to know the number of times of get ‘Head’ and ‘Tail’. You keep the record as ‘I’ (one) for getting ‘Head’ and ‘0’ (zero) for ‘Tail’. Write a program for the above task. Suppose, you have tossed a coin 20 times in this game.
Read Answer
You want to calculate the sum of all positive even numbers and the sum of all negative odd numbers from a set of numbers.

This Java program takes a set of numbers from the user and calculates the sum of all positive even numbers and the sum of all negative odd numbers. The program uses loops and conditional statements to determine the sums based on user input.

Read more
You want to calculate the sum of all positive even numbers and the sum of all negative odd numbers from a set of numbers. You can enter 0 (zero) to quit the program and thus it displays the result. Write a program to perform the about task.
Read Answer
Write a program in Java to accept 10 different numbers and display the greatest and the smallest of the numbers.

This Java program allows users to input 10 different numbers and then determines and displays the greatest and smallest numbers among them. The program demonstrates the use of arrays, loops, and conditional statements in Java.

Read more
Write a program in Java to accept 10 different numbers and display the greatest and the smallest of the numbers.
Read Answer
Write a program in Java to accept a number and check whether a number is perfect or not.

Here's a Java program that accepts a number from the user and checks whether it is a perfect number or not. A perfect number is defined as a positive integer that is equal to the sum of its proper divisors, excluding itself.

Read more
Write a program in Java to accept a number and check whether a number is perfect or not.
A number is said to be perfect if sum of the factors (including 1 and excluding the number itself) is the same as the original number
Example: Input: 6 is a perfect number, Factors of 6 = 1, 2, 3: Thus, 6 = 1 + 2 + 3, is a perfect number.

Read Answer
Write a program to accept a number and check whether the number is prime or not.

This program checks if a given number is prime: It accepts an integer input from the user. The checkPrime method determines if the number is prime by checking for factors from 2 up to the square root of the number. The program prints whether the number is prime or not.

Read more
Write a program to accept a number and check whether the number is prime or not.
[A prime number is divisible only by 1 (one) and the number itself.]
Read Answer
Write a program in Java to accept two numbers and find the Greatest Common Divisor (G.C.D.) of the two numbers.

This Java program prompts the user to input two numbers and calculates their Greatest Common Divisor (G.C.D.) using the Euclidean algorithm. The G.C.D. is displayed as the output.

Read more

Write a program in Java to accept two numbers and find the Greatest Common Divisor (G.C.D.) of the two numbers.

Read Answer
Write a program in Java to find the sum of any ten natural numbers.

This Java program prompts the user to input ten natural numbers and calculates their sum. It ensures that only natural numbers (greater than zero) are accepted. The program then displays the total sum of the entered numbers.

Read more
Write a program in Java to find the sum of any ten natural numbers.
Read Answer
Write a program based on the above criteria, to input a name, address, amount of purchase and the type of purchase (‘L’ for Laptop and ‘D’ for Desktop).

Here is a Java program based on the seasonal discount criteria for purchasing a Laptop or Desktop PC from an electronics shop.

Read more
An electronics shop has announced the following seasonal discounts on the purchase of certain items.

Category

Discount on Laptop

Discount on Desktop PC

Up to Rs. 25,000

0.0%

5.0%

Rs. 25,001 to Rs. 57,000

5.0%

7.5%

Rs. 57,001 to Rs. 1,00,000

7.5%

10.0%

More than Rs. 1,00,000

10.0%

15.0%

Write a program based on the above criteria, to input a name, address, amount of purchase and the type of purchase (‘L’ for Laptop and ‘D’ for Desktop). Compute and print the net amount to be a customer with his name and address.

[Hint: Discount = Discount rate/100 * Amount of purchase
Net amount = Amount of purchase – Discount]

Read Answer
Write a menu-driven program to input show room price and the number of years used (‘1’ for one year old, ‘2’ for two years old) and so on.

This Java program calculates the depreciated value of a car based on its showroom price and the number of years it has been used. It uses a switch-case structure to determine the applicable depreciation rate and calculates the depreciated value. The program then displays the original price, depreciated value, and the amount to be paid for the car.

Read more
You want to buy an old car from ‘Sale and Purchase’, where you can get a vehicle at a depreciated price. The depreciation value of a car is calculated on its showroom price and the number of years it has been used. The depreciated value of a vehicle is calculated as per the tariff given below:

No. of years used

Rate of depreciation

1

10%

2

20%

3

30%

4

50%

Above 4 years

60%

Write a menu-driven program to input show room price and the number of years used (‘1’ for one year old, ‘2’ for two years old) and so on. Calculate the depreciated value. Display the original price of the car, the depreciated value and the amount paid for the car.
Read Answer