P2Cart Logo
In what way can you use the input and output streams to enter and display the values?

This tutorial provides an overview of using input and output streams in Java, demonstrating how to read user input with the Scanner class and display values using System.out. It includes practical examples to help you understand stream operations in Java programming.

Read more
In what way can you use the input and output streams to enter and display the values?
Read Answer
What do you mean by library classes?

In programming, library classes refer to pre-defined classes provided by programming languages or frameworks that offer reusable functionality. These classes are part of a larger software library, which is a collection of code that developers can use to perform common tasks without having to write everything from scratch. Library classes can include utilities for data manipulation, networking, file handling, graphics rendering, and more.

Read more
What do you mean by library classes? Write any five library classes.
Read Answer
Write a menu-driven program to perform the following tasks by using the Switch case statement

This Java program utilizes a menu-driven approach to perform mathematical tasks, allowing users to print a specific series or calculate the sum of a series of fractions. The program demonstrates the use of switch case statements for clear task management and user interaction.

Read more
Write a menu-driven program to perform the following tasks by using the Switch case statement:
a)      To print the series:
       0, 3, 8, 15, 24, …………. to n terms. (value of ‘n’ is to be an input by the user)
b)      To find the sum of the series:
       S = 1/2 + 3/4 + 5/6 + 7/8 + ………… + 19/20

Read Answer
Write a menu-driven program to accept a number from the user and check whether it is a Prime number or an Automorphic number.

This Java program allows users to determine whether a given number is a prime number or an automorphic number using a menu-driven interface. The program efficiently checks each condition and displays the appropriate results based on user input.

Read more
Write a menu-driven program to accept a number from the user and check whether it is a Prime number or an Automorphic number.
a)      Prime number: (A number is said to be prime if it is divisible by 1 and itself).
     Example: 3, 5, 7, 11 ……………..
b)      Automorphic number: (Automorphic number is the number, which is contained in the last digit (s) of it is square).
     Example: 25 is an Automorphic number as it is square is 625 and 25 is present as the last two digits.

Read Answer
Write a program to input the name and the amount of tickets for the customer.

This Java program calculates the discount on ticket charges for customers of Shasha Travels Pvt. Ltd. based on a tiered discount rate. For each customer, it computes the discount, the net payable amount, and displays a formatted summary of all customer data.

Read more
Shasha Travels Pvt. Ltd. Gives the following discount to its customers:

Ticket Amount

Discount

Above Rs. 70,000

18%

Rs. 55,001 to Rs. 70,000

16%

Rs. 35,001 to Rs. 55,000

12%

Rs. 25,001 to Rs. 35,000

10%

Less than Rs. 25,001

2%

Write a program to input the name and the amount of tickets for the customer. Calculate the discount and net amount to be paid. Display the output in the following format for each customer:

Sl. No.

Name

Ticket Charge

Discount

Net Amount

1

xxxxx

xxxxxx

xxxxx

xxxxxx

 (Assume that there are 15 customers, the first customer is given the serial number 1, the next customer 2, and so on).
Read Answer
Write a menu-driven program to accept a number from the User and check whether it is a ‘BUZZ’ number or to accept any two numbers and print the ‘GCD’ of them.

This Java program allows users to check if a given number is a Buzz number or calculate the GCD of two numbers using the Euclidean algorithm. Users can select an option from a menu for the desired operation and input numbers for real-time calculation and display.

Read more
   Write a menu-driven program to accept a number from the User and check whether it is a ‘BUZZ’ number or to accept any two numbers and print the ‘GCD’ of them.
a)      A ‘BUZZ’ number is a number that either ends with 7 or is divisible by 7.
b)      GCD (Greatest Common Divisor) of two integers is calculated by the continued division method. Divide the larger number by the smaller, the remainder then divides the previous divisor. The process is repeated till the remainder then zero. The divisor then results from the GCD.

Read Answer
Write a program to generate a triangle or an inverted triangle till n terms based upon the User’s triangle to be displayed.

This Java program lets users generate either a triangle or an inverted triangle pattern up to n terms based on their choice. It dynamically adjusts the pattern based on the number of terms and choice, making it ideal for exploring loop-based pattern generation.

Read more
Write a program to generate a triangle or an inverted triangle till n terms based upon the User’s triangle are displayed.

Example 1:

Input: Type 1 for a triangle and type 2 for an inverted triangle

Enter your choice 1

Enter the number of terms 5

Sample Output:

1

2  2

3  3  3

4  4  4  4

5  5  5  5  5

Example 2

Input: Type 1 for a triangle and type 2 for an inverted triangle

Enter your choice 1

Enter the number of terms 6

Sample Output:

6  6  6  6  6  6

5  5  5  5  5

4  4  4  4

3  3  3

2  2

1

Read Answer
A class teacher wants to know the performance of the students of her class in Science (Physics, Chemistry, Biology).

This Java program helps a class teacher analyze the performance of 45 students in Science (Physics, Chemistry, Biology) by calculating each student’s average score. It counts the number of students achieving an average of 90% or higher and displays this count at the end.

Read more
A class teacher wants to know the performance of the students of her class in Science (Physics, Chemistry, Biology). Write a program to accept marks in Physics, Chemistry and Biology of each student. Calculate the average and count how many of than have secured 90% or more (on average) in the class having 45 students. 
Read Answer
Write a Program to simulate a game of throwing dice 10 times, 100 times and 1000 times.

This Java program simulates rolling a die 10, 100, and 1000 times, calculates the total score for each set, and displays the results.

Read more
Write a Program to simulate a game of throwing dice 10 times, 100 times and 1000 times. Print the score obtained in each category.
Read Answer
A game of throwing dice, is played between two players in which, each player throws a dice unless his score adds up to 20.

This Java program simulates a dice game where two players take turns rolling a die. Each player's goal is to reach a score of 20 or more with the fewest number of throws. The program outputs the number of throws and declares the winner.

Read more
A game of throwing dice is played between two players in which, each player throws a dice unless his score adds up to 20. A player is declared ‘Winner’ with the minimum number of throws. Write a program to perform the task given above.
Read Answer
Some answer scripts with scores 0 to 99 awarded after marking are to be searched

This Java program analyzes answer scripts by calculating the total number of scripts, the percentage of candidates scoring 85 and above, and the percentage of candidates scoring 39 and below. It accepts the number of scripts and their corresponding scores from the user and displays the results.

Read more
     Some answer scripts with scores 0 to 99 awarded after marking are to be searched for finding:
a)      Number of answer scripts marked;
b)      Percentage of candidates getting 85 and above;
c)      Percentage of candidates getting 39 or less;
d)      Write a Java program to take the scores as inputs and then output the three quantities required.

Read Answer
The Sum of the cubes of the natural numbers is given by the following formula:

This Java program calculates the sum of the cubes of the first n natural numbers using the formula � = ( � ( � + 1 ) 2 ) 2 S=( 2 n(n+1) ​ ) 2 . Users input the value of n, and the program computes and displays the result based on the derived formula. The program demonstrates basic arithmetic operations and input/output handling in Java.

Read more
   The Sum of the cubes of the natural numbers is given by the following formula:
13 + 23 + 33 + ……….. + n3
       = [n (n+10)/2]2
It is intended to write a program to compute the value of S, where

S = 33+ 43+ 53+ ……… + n3

a)    State :
a.       The variable whose value is to be taken as input.
b.      The variable whose value is to be obtained as input.
b)      Break up the processing job into four sequential steps and write those steps.
c)      Write a program in JAVA to find S.

Read Answer
A computerized ticket counter of an underground metro rail station charges for each ride at the following rate

This Java program simulates a computerized ticket counter for an underground metro rail station, calculating fares based on passenger age groups. It takes input for the number of passengers, determines fare rates, and summarizes the total number of passengers and the total fare collected. Ideal for public transportation systems, the program effectively manages ticket sales and passenger data.

Read more
A computerized ticket counter of an underground metro rail station charges for each ride at the following rate:

Age

Amount/Head

18 or above

Rs. 5

5 or above but below 18

Rs. 3

Accompanying kids below 5

Nil

Write a program in Java, which takes as input the number of people of various age groups and prints a ticket. At the end of the journey, the program states the number of passenger of different age groups who travelled and the total amount receives as collection of fares.
Read Answer
Computer company has 96 employees who are divided into 4 grades as per their basic pay as the following:

This Java program calculates the monthly salary slips for 96 employees based on their grades and basic pay. It computes the Dearness Allowance (D.A.), House Rent (H.R.), and any applicable income tax deductions. The program provides a detailed pay slip for each employee, showing their total salary and net pay after tax deductions.

Read more
A computer company has 96 employees who are divided into 4 grades as per their basic pay as the following:

Grade 1 Basic

D.A.

H.R.

Rs. 10,000 P.M. or more

40% of Basic

30% of basic

Grade 2 Basic

D.A.

H.R.

Rs. 5,000 P.M. or more but less than 10,000

40% of Basic

25% of Basic

Grade 3 Basic

D.A.

H.R.

Less than Rs. 5,000 but more than 2,000 P.M.

30% of Basic

20% of Basic

Grade 4 Basic

D.A.

H.R.

Rs. 2,000 P.M. or less

30% of Basic

15% of Basic

 If the salary, which is the total of Basic, D.A. and H.R. is above Rs. 50,000 per annum then income tax at the rate of 30% of the annual salary exceeding Rs. 50,000 is deducted on monthly basic at source. Taking the name of the employee and the basic (monthly) pay as inputs a pay slip for each employee is to be printed. Write a program in Java to perform the job. 
Read Answer
In an election, out of 1249 voters in a booth, only 861 voters used their franchise correctly.

This Java program computes the election results for an election with five candidates. It accepts the number of valid votes and calculates the invalid votes based on the total voters. Additionally, it calculates and displays the percentage of valid votes received by each candidate, providing a clear overview of the election outcomes.

Read more
   In an election, out of 1249 voters in a booth, only 861 voters used their franchise correctly. If five candidates are contesting, write a program in Java to find:
a)      The number of invalid and valid votes and
b)      The percentage of the valid votes received by each candidate.

Read Answer
On the basic sale, a pharmaceutical company announces the following new tariff of commission for their Medical Representatives and Distributors.

This Java program calculates the commissions for 50 medical representatives and their distributors based on a specified sales tariff. It accepts monthly sales input, computes commissions, and displays the results in a structured table format, allowing for easy comparison and analysis.

Read more
On the basic sale, a pharmaceutical company announces the following new tariff of commission for their Medical Representatives and Distributors.

Sale

Commission of Representative

Commission of Distributor

Up to Rs. 10000

5%

2%

Rs. 10001 to Rs. 20000

8%

3%

Rs. 20000 to Rs. 30000

10%

4%

More than Rs. 30000

12%

5%

Write a program to accept monthly sales from 50 different representatives along with their distributors. Calculate their commissions and display the output in the given format:

Sl. No.

Sale

Commission of Representative

Commission of Distributor

xxx

xxx

xxx

xxx

Read Answer
Write a program to find the sum of the given series: a) S = a + a2/2 + a3/3 + ………… + an/n.........................

The provided Java programs calculate the sum of various mathematical series based on user-defined inputs for a and n. Each program implements a specific formula, demonstrating the use of loops and mathematical operations to achieve the desired output.

Read more
     Write a program to find the sum of the given series:
a)      S = a + a2/2 + a3/3 + ………… + an/n
b)      S = a + a/2! + a/3! + ………… + a/n!
c)      S = a/2 + a/4 + a/8 + ……….. to n
d)      S = 1 - a/2 + 3 - a/4 + 5 - a/6 + ………….. to n
e)      S = a/2! - a/3! + a/4! + a/5! + …………. + a/20!
f)       S = (a+1) + (a+2) + (a+3) + ……………. + (a + n)
g)      S = a+1/3 + a+2/5 + a+3/7 + ……….. to n
h)      S = a/2 + a/5 + a/8 + a/11 + ………….. a/20
i)        S = 1/a +2/a2 + 3/a3 + ………… n/an
j)        S = a1 - a3/5 + a5/9 - a7/13 …………… to n

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

This Java program computes the sum of various mathematical series, including Fibonacci, arithmetic progressions, and factorial series. It prompts the user for the number of terms n and performs calculations based on different series, displaying the sum of each.

Read more
   Write a program in Java to find the sum of the given series:
a)      S = 9 + 99 + 89 + 7 + ………….. to n
b)      S = 1 + 1 + 2 + 3 + 5 + ……….. to n terms
c)      S = 2 – 4 + 6 – 8 + ………. to n
d)      S = (1*2) + (2*3) + ………. + (19*20)
e)      S = 1 + (1+2) + (1+2+3) + ……….. + (1+2+3+……. + n)
f)       S = 1 + (1*2) + 2 + (1*2*3) + 3 ………. + 9 + (1*2*3*………..10)
g)      S = 1! + 2! + 3! + 4! + …………. to n terms
h)      S = 1/2 + 2/3 + 3/4 + ……… to n terms
i)        S = 1 + 3/4 + 5/9 + ……… to n terms
j)        S = 2/3 - 4/5 + 6/7 - 8/9 + ………… to n

Read Answer
Write a program to accept two numbers and check whether they are twin prime or not.

This Java program checks if two user-input numbers are twin primes. Twin primes are pairs of prime numbers whose difference is exactly 2, such as (11, 13) or (17, 19).

Read more
Write a program to accept two numbers and check whether they are twin prime or not.
[Hint: Twin prime numbers are the prime numbers whose difference is two. E.g.:(5,7),(11,13)……..]

Read Answer
Write a program to accept two numbers and find the Lowest Common Multiple (LCM) of the numbers.

This Java program accepts two numbers from the user and calculates their Lowest Common Multiple (LCM) using the formula that relates LCM with HCF (Highest Common Factor). The program also computes HCF using the Euclidean algorithm.

Read more
Write a program to accept two numbers and find the Lowest Common Multiple (LCM) of the numbers.
[Hint: LCM = Product of two numbers/HCF]

Read Answer