Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Assignment no.

1
To be submitted by Thursday 7th October beginning of lecture in hard form

Q1. Write an application that inputs a number consisting of five digits from the user,
separates the number into its individual digits and prints the digits separated from one another
by a space each. For example, if the user types in the number 42339, the program should print
42339
Q2. Write an application that calculates the squares and cubes of the numbers from 0 to 10
and prints the resulting values in table format, as shown below:

Q3. Create an application that calculates your daily driving cost, so that you can estimate how
much money could be saved by car pooling, which also has other advantages such as
reducing carbon emissions and reducing traffic congestion. The application should input the
following information and display the user’s cost per day of driving to work:
a) Total miles driven per day.
b) Cost per litre of petrol.
c) Average miles per litre.
Q4. Body Mass Index Calculator. The formulas for calculating BMI are:

Create a BMI calculator that reads the user’s weight in pounds and height in inches (or, if you
prefer, the user’s weight in kilograms and height in meters), then calculates and displays the
user’s body mass index. Also, display the following information from the Department of
Health and Human Services/National Institutes of Health so the user can evaluate his/her
BMI
Q5. (Salary Calculator) Develop a Java application that determines the gross pay for each of
three employees. The company pays straight time for the first 40 hours worked by each
employee and time and a half for all hours worked in excess of 40. You’re given a list of the
employees, their number of hours worked last week and their hourly rates. Your program
should input this information for each employee, then determine and display the employee’s
gross pay. Use class Scanner to input the data.
Q6. Write the source code that uses nested for loops to print the following patterns in Java
a)
*
***
*****
*******
*********
For 5 rows, there are 4 spaces before the first *
Spaces get decremented by 1 on each row

b)
************
*0*0*0*0*0*0
************
*0*0*0*0*0*0
************

c)
$*****
*$****
**$***
***$**
****$*
*****$
d)
*
**
***
****
*****
****
***
**
*

e)
BBBBBBBBB
.BBBBBBB
..BBBBB
...BBB
....B

Q7. Use switch statement to use the weekday number to calculate the weekday name. Start
Monday as day 1.

Q8. Write a do-while loop that asks the user to enter two numbers. The numbers should be
added and the sum displayed. The loop should ask the user whether he or she wishes to
perform the operation again. If so, the loop should repeat; otherwise it should terminate. 

Q9. Write a program to enter the numbers till the user wants and at the end it should display
the count of positive, negative and zeros entered. 

Q10. Write a program to enter the numbers till the user wants and at the end the program
should display the largest and smallest numbers entered.

*****

You might also like