0% found this document useful (0 votes)
4 views

Assignment - Basic Constructs and Control Statements

fundamental assignment in java
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment - Basic Constructs and Control Statements

fundamental assignment in java
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment – Basic Constructs and Control Statements

1. Write an application that asks the user to enter two integers, obtains them from the user and
displays the larger number followed by the words "is larger" . If the numbers are equal, print the
message "These numbers are equal" .

2. Write an application that inputs one number consisting of five digits from the user, separates the
number into its individual digits and prints the digits separated from one another by three spaces
each. For example, if the user types in the number 42339 , the program should print
4 2 3 3 9
Assume that the user enters the correct number of digits. What happens when you execute the
program and type a number with more than five digits? What happens when you execute the pro-
gram and type a number with fewer than five digits?

3. Write a program that inputs five numbers and determines and prints the number of negative
numbers input, the number of positive numbers input and the number of zeros input.

4. 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.

5. Write an application that prompts the user to enter the size of the side of a square, then displays a
hollow square of that size made of asterisks. Your program should work for squares of all side
lengths between 1 and 20

6. A palindrome is a sequence of characters that reads the same backward as forward. For example,
each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an
application that reads in a five-digit integer and determines whether it’s a palindrome. If the number
is not five digits long, display an error message and allow the user to enter a new value.

7. A right triangle can have sides whose lengths are all integers. The set of three integer values for
the lengths of the sides of a right triangle is called a Pythagorean triple. The lengths of the three
sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the
square of the hypotenuse. Write an application that displays a table of the Pythagorean triples for
side1 , side2 and the hypotenuse , all no larger than 500.

8. Factorials are used frequently in probability problems. The factorial of a positive integer n
(written n! and pronounced “n factorial”) is equal to the product of the positive integers from 1 to n.
Write an application that calculates the factorials of 1 through 20. Use type long . Display the
results in tabular format. What difficulty might prevent you from calculating the factorial of 100?

You might also like