Examples with data and arithmetic operators in JAVA
Examples descriptionExamples are exercises
|
Installing JAVA JDK and Netbeans IDE |
- If you have N hours today (and you will surely have more than 2 J), how many hours will it be, and how many minutes will it be after the last time is over?
- On the chessboard of width nn and length mm, the upper left field is white. Write a program that determines the number of black fields on a given chessboard.
- Write a program that throws out hundreds of numbers from the decimal number.
Example for exersise
4.The football field
The athlete is heated at the beginning of the training by running along the edges of the rectangular terrain length d and the width s. Write a program that determines how many meters the athletes run through until the field hits.
5.Average car speed
Two cities A and B are located at a distance of 200 km, while the distance between cities B and C is S2 [km / h] (User input). A car moving from place A to place B at some speed v1 arrives at place B in 3h, and then continues to move to place C at some speed v2. If he traveled 5 hours from place B to C, determine the average speed on the entire road from A to C.
6.The map
Data is a map at which the distance of 1cm represents S km in nature. If the distance on the map between the two uninhabited X cm points is to determine their actual distance.
7.Volume of the cylinder
Write a program that calculates the area and volume of the cylinder, which is the radius of the base R, and the height H.
8.Converting the angle
The angle is given in degrees to two decimal places. Write a program to give the angle expressed in degrees and minutes. For example 60.25 present as 60 degrees and 15 minutes.
9.Travel
The family went on vacation by car. They should travel by car from kilometers moving at a steady speed of v [km / h]. Write a program that determines how many kilometers will be covered in t hours.
Solution: The task is solved on the page Preparation for test 1
Solution: The task is solved on the page Preparation for test 1
10. Distance between houses
Pera and Mika live in the same street, Mika's house is further away from the school. They go to school the same way, leave the house at the same time and move evenly. Pera moves at v1m / s, and Mika at v2m / s (v2> v1). Write a program that determines the distance between their houses, if after t seconds Mika was d meters behind Pera.
Solution: The task is solved on the page Exercises for testing 1
Source: Loop, Arithmetic. Formulas. Movement
Solution: The task is solved on the page Exercises for testing 1
Source: Loop, Arithmetic. Formulas. Movement
11. Swimming pool
During the storm, n liters of water per square meter fell. Write a program that determines how many centimeters the water level is raised in the open pool of the given dimensions, if we know that the water did not spill over the pool.
12. Time conversion
Load time in seconds and print in the form hh: mm: ss
13. The end of today's classes
Today your first school time starts at 08:00 AM. One school time lasts 45 minutes, a small break between classes takes 5 minutes and a big break lasts 20 minutes. A big break is after 2 o'clock, and small breaks are after all others.
14. Digit in place of hundred
Write a program that extracts the digit hundreds from the decimal notation of the number.
15. The rectangle gives the coordinates of two opposite ends
The coordinates of the two opposite vertices of the rectangle whose sides are parallel to the coordinate axes are given. Write a program that shows the length of the diagonal, the volume, and the surface of that rectangle.
Input
From the standard input, 4 integers are loaded from the interval [-1000, 1000], each in a separate line. The numbers loaded are x and y coordinates of the two opposite vertices of the rectangle.
Output
On the standard output, show the length of the diagonal of the rectangle, rounded to two decimal places, the volume and the surface of the given rectangle. Each data is shown in a separate line.
Example
Input
5
-1
-3
6
Output
10.63
30
56
16. Change
In the country of Tarzania, there are only small coins (1, 2, 5 or 10 jukku). Vendors often have a problem with returning cusps, and developers help their programs to solve this problem. Write the KUSUR program that will give you the value of P for the value P and the value V given by the customer, and determine how much of the money can be paid to the buyer as a buyer. Assume that the cashier has enough money (1, 2, 5 or 10 jukku), and that the exact amount of cousins is always returned (ie, the cashier will not give the chew or remain liable to the buyer). The values of P and V are two integers that are loaded from the first line of the standard input and are separated by a blank character.
Example
Input
14 20
Output
2
Explanation: The seller will return the curfew with a total of two coins (one of 5 dinars and one of 1 dinars), and will not return a curd with three coins (each two dinars).
Source: www.petlja.org/biblioteka/r/Problems/-27
Input
14 20
Output
2
Explanation: The seller will return the curfew with a total of two coins (one of 5 dinars and one of 1 dinars), and will not return a curd with three coins (each two dinars).
Source: www.petlja.org/biblioteka/r/Problems/-27
17. N Day Training
Waterpolo Marko takes part in the preparations for the competition in duration of n days. On the first day of preparation, Marko swims a meter, and every next day for d meters more than the previous day. Write a program that determines how many meters Marko intertwines on the last day of preparationa.
Input
Three natural numbers are entered, each in a special line of the standard input. The numbers in a row represent the number of days for which the preparations last n (n≤20), how many meters of Marko crosses the first day of preparation a (a≤3000), how many meters every day Marko swims more than the previous day d (d≤1000).
Output
At the standard exit, show how many meters of Marko sail on the last day of preparation.
Example
Input
10
500
100
Output
1400
Three natural numbers are entered, each in a special line of the standard input. The numbers in a row represent the number of days for which the preparations last n (n≤20), how many meters of Marko crosses the first day of preparation a (a≤3000), how many meters every day Marko swims more than the previous day d (d≤1000).
Output
At the standard exit, show how many meters of Marko sail on the last day of preparation.
Example
Input
10
500
100
Output
1400
18. Competitors
Two runners run along a circular track of length [km], at a speed of v1 [km / h], at a second speed of v2 [km / h]. How long will it take a faster runner to overclock the whole round?
Input
Data on two decimals:
The integer values of the number of hours, minutes and seconds, representing the time required for a faster runner for the whole circuit, will catch up slower. Sequences are displayed rounded to the nearest integer value.
Example
Input
10.00
5.00
6.00
Output
10
0
0
Data on two decimals:
- s - length of the circular path (0≤s≤10)
- v1 - speed of the first runner (1≤v1≤45)
- v2 - the speed of the second runner (1≤v2≤45)
The integer values of the number of hours, minutes and seconds, representing the time required for a faster runner for the whole circuit, will catch up slower. Sequences are displayed rounded to the nearest integer value.
Example
Input
10.00
5.00
6.00
Output
10
0
0
19. Clock angle
If the angle is given which the hourglobe closes with the vertical half-center that connects the center and the top of the clock (number 12), specify the time in minutes and seconds.
Input
From the standard input, there is an entire number that represents the angle in degrees.
Output
On the standard output, print two integers h (0≤h <12) and m (0≤m <60) which represent the number of hours and minutes closest to the clock position.
Example
Input
90
Output
3: 0
From the standard input, there is an entire number that represents the angle in degrees.
Output
On the standard output, print two integers h (0≤h <12) and m (0≤m <60) which represent the number of hours and minutes closest to the clock position.
Example
Input
90
Output
3: 0
20. Apples in the triangle:
Apples are embedded in a triangle of the following shape::
*
**
***
****
Write a program that determines the total number of apples in the triangle.
Input
From the standard input, an integer n (3⋅10 ^ 9≤6⋅10 ^ 9) is entered which determines the number of rows of triangles.
Output
On the standard output, print an entire number that represents the total number of apples in the triangle.
Example
Input
3500000000
Output
6125000001750000000
Example2
Input
5000000000
Output
12500000002500000000
From the standard input, an integer n (3⋅10 ^ 9≤6⋅10 ^ 9) is entered which determines the number of rows of triangles.
Output
On the standard output, print an entire number that represents the total number of apples in the triangle.
Example
Input
3500000000
Output
6125000001750000000
Example2
Input
5000000000
Output
12500000002500000000
|
Next
Selection statements - examples >| |

