Programming Assignment-II
(Command Line Argument & Keyboard Input)
Using Command-Line Arguments
1.Write a java program that takes two positive integers as command-line arguments
and prints true if either evenly divides the other.
2. Write a java program that takes three positive integers as command-line arguments
and prints true if any one of them is greater than or equal to the sum of the other two
and false otherwise. (Note: This computation tests whether the three numbers could be
the lengths of the sides of some triangle.)
3. Write a java program that takes two int values a and b from the command line and
prints a random integer between a and b.
4. Write a java program that prints the sum of two random integers between 1 and 6
(such as you might get when rolling dice).
5. Write a java program that takes a double value t from the command line and prints
the value of sin (2t) + sin (3t).
6. Write a java program that takes three double values x0 , v0 , and t from the
command line and prints the value of (x0 + v0t + gt 2 ) / 2, where g is the constant
9.78033. (Note: This value the displacement in meters after t seconds when an object
is thrown straight up from initial position x0 at velocity v0 meters per second.)
7. Write a program that takes two int values m and d from the command line and
prints true if day d of month m is between 3/20 and 6/20, false otherwise.
8. Write a java program that calculates the monthly payments you would have to
make over a given number of years to pay off a loan at a given interest rate
compounded continuously, taking the number of years t, the principal P, and the
annual interest rate r as command-line arguments. The desired value is given by the
formula Pert . Use Math.exp ().
Page 1 of 3
9. Write a java program that takes three double values x, y, and z as command-line
arguments and prints true if the values are strictly ascending or descending ( x < y < z
or x > y > z ), and false otherwise.
10. Write a java program that prints five uniform random values between 0 and 1,
their average value, and their minimum and maximum value. Use Math.random(),
Math.min(), and Math.max().
11. Write a program that takes three int values from the command line and prints them
in ascending order. Use Math.min() and Math.max().
Using Keyboard Input
12. Write a java program which requests the user to enter a number. The number and
the square of the number are then printed on the same line. For example, if 4 is
entered, the program outputs:
Number=4 Square of Number=16
13. Write a java program to input some kind of information of a person from the
keyboard.
Age of a person
Height of a person
Weight of a person
and display it in the following manner. e.g.
So, you're 35 years old, 6'2" tall and 60KG heavy.
14. Input the basic salary of an employee of an organization through the keyboard.
His dearness allowance (DA) is 40% of basic salary, and house rent allowance (HRA)
is 20% of basic salary. Write a java program to calculate his gross salary.
Page 2 of 3
15. Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a
java program to convert this temperature into Centigrade degrees.
16. The length & breadth of a rectangle and radius of a circle are inputted through the
keyboard. Write a java program to calculate the area & perimeter of the rectangle, and
the area & circumference of the circle.
17. Write a java program that helps the user count his change. The program should
ask how many 25 paisa users have, then how many 50 paisa, then how many one
rupees. Then the program should tell the user how much money he has, expressed in
rupees.
18. If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left over.
(This is essentially the definition of the / and % operators for integers.) Write a java
program that asks the user how many eggs she has and then tells the user how many
dozen eggs she has and how many extra eggs are left over. A gross of eggs is equal to
144 eggs.
Extend your program so that it will tell the user how many gross, how many dozen,
and how many left over eggs she has. For example, if the user says that she has 1342
eggs, and then your program would respond with
Your number of eggs is 9 gross, 3 dozen, and 10.
Page 3 of 3