Write a Java program to print 'Hello' on screen and then print your name on a separate line. Expected Output: Hello Donald Trump

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

1.Write a Java program to print 'Hello' on screen and then print your name on a separate
line.
Expected Output:
Hello
Donald Trump
2. A school has following rules for grading system:
a. Below 25 - F
b. 25 to 45 - E
c. 45 to 50 - D
d. 50 to 60 - C
e. 60 to 80 - B
f. Above 80 - A
Ask user to enter marks and print the corresponding grade.
3. Create a function that takes two numbers as arguments and returns the GCD of the two
numbers.
Examples
gcd(3, 5) ➞ 1
gcd(14, 28) ➞ 14
gcd(4, 18) ➞ 2
4. Given an integer, create a function that returns the next prime. If the number is prime,
return the number itself.
Examples
nextPrime(12) ➞ 13
nextPrime(24) ➞ 29
nextPrime(11) ➞ 11
// 11 is a prime, so we return the number itself.
5. Write a Java program that takes two numbers as input and display the product of two
numbers.
Test Data:
Input first number: 25
Input second number: 5
Expected Output:
25 x 5 = 125

Page 2 of 4

6. Write a Java program to print the sum (addition), multiply, subtract, divide and remainder
of two numbers.
Test Data:
Input first number: 125
Input second number: 24
Expected Output:
125 + 24 = 149
125 - 24 = 101
125 x 24 = 3000
125 / 24 = 5
7. Write a Java program that takes a number as input and prints its multiplication table upto
10.
Test Data:
Input a number: 8
Expected Output:
8 x 1 = 8
8 x 2 = 16
8 x 3 = 24
8 x 10 = 80
8. Create a function that finds how many prime numbers there are, up to the given integer.
Examples
primeNumbers(10) ➞ 4
// 2, 3, 5 and 7
primeNumbers(20) ➞ 8
// 2, 3, 5, 7, 11, 13, 17 and 19
primeNumbers(30) ➞ 10
// 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29
9. Write a Java program to compute a specified formula.
Specified Formula:
4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11))
Expected Output
2.9760461760461765
10. Write a Java program to print the area and perimeter of a circle.
Test Data:
Radius = 7.5
Expected Output
Perimeter is = 47.12388980384689
Area is = 176.71458676442586
11. Write a Java program that takes three numbers as input to calculate and print the average
of the numbers.
12. Write a Java program to print the area and perimeter of a rectangle.
Test Data:
Width = 5.5 Height = 8.5
Expected Output
Area is 5.6 * 8.5 = 47.60
Perimeter is 2 * (5.6 + 8.5) = 28.20
13. Write a Java program to swap two variables.

Page 3 of 4
14. Write a Java program to compare two numbers.
Input Data:
Input first integer: 25
Input second integer: 39
Expected Output
25 != 39
25 < 39
25 <= 39
15. Write a Java program and compute the sum of the digits of an integer.
Input Data:
Input an integer: 25
Expected Output
The sum of the digits is: 7
16. Write a Java program to print the odd numbers from 1 to 99. Prints one number per line.
Sample Output:
1
3
5
....
97
99
17. Create a function that takes an integer n and reverses it.
Examples
rev(5121) ➞ "1215"
rev(69) ➞ "96"
rev(-122157) ➞ "751221"
Notes
This challenge is about using two operators that are related to division.
If the number is negative, treat it like it's positive.
18. Write a Java program to calculate the sum of two integers and return true if the sum is
equal to a third integer.
Sample Output:
Input the first number : 5
Input the second number: 10
Input the third number : 15
The result is: true
19. Write a Java program that accepts three integer values and return true if one of them is 20
or more and less than the subtractions of others.
Sample Output:
Input the first number: 15
Input the second number: 20
Input the third number: 25
false
20. Write a Java program that accepts two integer values between 25 to 75 and return true if
there is a common digit in both numbers.
Sample Output:
Input the first number : 35
Input the second number: 45
Result: true

Page 4 of 4

21. Write a Java program to compute the sum of the first 100 prime numbers.
Sample Output:
Sum of the first 100 prime numbers: 24133

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education