0% found this document useful (0 votes)
6 views3 pages

JAVA Exercises

The document outlines a series of programming exercises that cover basic concepts in programming, including user input, arithmetic operations, conditional statements, and loops. Each exercise provides a specific task, such as displaying values, calculating BMI, or generating patterns. The exercises are designed to help users practice and reinforce their programming skills in Java.

Uploaded by

hfw555cfwd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

JAVA Exercises

The document outlines a series of programming exercises that cover basic concepts in programming, including user input, arithmetic operations, conditional statements, and loops. Each exercise provides a specific task, such as displaying values, calculating BMI, or generating patterns. The exercises are designed to help users practice and reinforce their programming skills in Java.

Uploaded by

hfw555cfwd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exercise 1:

Write a program that takes a number from the user and then displays on the screen the number given by
the user preceded by the message "your given value is:".....
Execution example:
Enter a value: 16
The given value is: 16

Exercise 2:
Write a program that asks the user to enter the day, month, and year, then displays the date on the screen
as Day/Month/Year.
Example execution:
Day =11
Month =7
Year =2013
The date you gave is 7/11/2013

Exercise 3:
Write a program that enters 2 integers and successively displays the sum, the difference, the product,
and the quotient of these 2 integers. Below is a simple run of the program showing you the form of the
output.
Simple execution: Give the
two values: 12 8 ↵
12 + 8 = 20
12 – 8 = 4
12 * 8 =96
12 / 8 = 1
12 % 8 = 4

Exercise 4:
Write a program that reads an integer on the keyboard representing an amount in euros and convert it
into dollars, little reminder: 1 euro = 1.30 dollars,
Execution example:
Given sum to convert: 250
The converted amount is 325 dollars

Exercise 5:
Write a program that asks the user to type 2 integers A and B and swapped the value of A and B (SWAP).

Exercise 6:
Write a program that asks the user to type in the width and height of a rectangle, then outputs to screen
the area and perimeter of that rectangle.

Page 1|3
Exercise 7:
Write a program that evaluates the value of f(x)=ax2+bx+c for an x given by the user. The values of a,
b, c is also given by the user.

Simple execution:
Give the coefficients a, b, and c of the function:
213↵
Give x: 2
f(2) = 2*2^2+1*2+3 = 13

Exercise 8:
Write a java program to check if a triangle is equilateral, isosceles, or scalene.
Test data:
50 50 60
Expected production:
It is an isosceles triangle.

Exercise 9:
Write a program that calculates the BMI (body mass index) which is a measure to estimate the
corpulence of a person. BMI is calculated based on height and mass using the following formula:

BMI= (Mass in Kg)/ (height in m) 2

The margins of the BMI values in the following table give an indication of the situation of the person's
body.

Exercise 10:
Write a program to read the temperature in degrees centigrade and display an appropriate message based
on the temperature status below(if).
• Temp <0 then freezing weather.
• Temp 0-10 then very cold weather
• Temp 10-20 then cold weather
• Temp 20-30 then Normal in Temp
• Temp 30-40 then it's hot
• Temp >= 40 so it's very hot

Page 2|3
Exercise 11:
Write a JAVA program to check if an alphabet is a vowel or a consonant (use the Switch).
Test data:
k
Expected production:
The alphabet is a consonant.

Exercise 12:
Using a while loop, write code that reads 10 integers from the user and displays their minimum.
Test data:
Enter an integer:5
Enter another integer: 17
Enter another integer: 22
Enter another integer: 79
Enter another integer: 10
Enter another integer: 3
Enter another integer: 52
Enter another integer: 99
Enter another integer: 120
Enter another integer: 14
The minimum is: 3

Exercise 13:
Write a program that calculates the sum of the values of the following series for a value n given by the
user:
1/1+1/2+1/3+⋯+1/n

Exercice 14 :
Écrire un programme pour générer le modèle suivant

a)
1
12
12 3
1234
b)
*
* *
* * *
* * * *

Page 3|3

You might also like