Convert Meters To Kilometers - Problem Description
Convert Meters To Kilometers - Problem Description
Problems for exercises and homework for the "Programming Fundamentals" course @ SoftUni.
You can check your solutions in Judge.
Examples
Input Output
1852 1.85
798 0.80
2. Pounds to Dollars
Write a program that converts British pounds to US dollars formatted to the 3rd decimal point.
1 British Pound = 1.36 Dollars
Examples
Input Output
80 108.800
39 53.040
Examples
Input Output
3 1000000000000000015
100000000000000000
0
5
10
2 333333333333.30000000003
0.00000000003
333333333333.3
Hints
Use BigDecimal not to lose precision.
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output
London City of London has population of 9002488 and area 1572 square
9002488 km.
1572
Rome City of Rome has population of 4355725 and area 1285 square
4355725 km.
1285
5. Concat Names
Read two names and a delimiter. Print the names joined by the delimiter.
Examples
Input Output
John John->Smith
Smith
->
Jan Jan<->White
White
<->
Linda Linda=>Terry
Terry
=>
6. Chars to String
Write a program that reads 3 lines of input. On each line, you get a single character. Combine all the characters into
one string and print it on the console.
Examples
Input Output
a abc
b
c
% %2o
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
7. Reversed Chars
Write a program that takes 3 lines of characters and prints them in reversed order with a space between them.
Examples
Input Output
A C B A
B
C
1 & L 1
L
&
8. Lower or Upper
Write a program that prints whether a given character is upper-case or lower-case.
Examples
Input Output
L upper-case
f lower-case
9. Centuries to Minutes
Write a program to enter an integer number of centuries and convert it to years, days, hours, and minutes.
Examples
Input Output
1 1 centuries = 100 years = 36524 days = 876581 hours = 52594877 minutes
5 5 centuries = 500 years = 182621 days = 4382906 hours = 262974384 minutes
Hints
Use appropriate data types to fit the result after each data conversion.
Assume that a year has 365.2422 days on average (the Tropical year).
Solution
You might help yourself with the code below:
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output
15 1 -> False
2 -> False
3 -> False
4 -> False
5 -> True
6 -> False
7 -> True
8 -> False
9 -> False
10 -> False
11 -> False
12 -> False
13 -> False
14 -> True
15 -> False
9 1 -> False
2 -> False
3 -> False
4 -> False
5 -> True
6 -> False
7 -> True
8 -> False
9 -> False
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
III. Variables
11. Refactor Volume of Pyramid
You are given a working code that finds the volume of a pyramid. However, you should consider that the variables
exceed their optimum span and have improper naming. Also, search for variables that have multiple purposes.
Code
Sample Code
Scanner scanner = new Scanner(System.in);
double dul, sh, V = 0;
System.out.print("Length: ");
dul = Double.parseDouble(scanner.nextLine());
System.out.print("Width: ");
sh = Double.parseDouble(scanner.nextLine());
System.out.print("Height: ");
V = Double.parseDouble(scanner.nextLine());
V = (dul * sh * V) / 3;
System.out.printf("Pyramid Volume: %.2f", V);
Hints
Reduce the span of the variables by declaring them at the moment they receive a value, not before
Rename your variables to represent their real purpose (example: "dul" should become length, etc.)
Search for variables that have multiple purposes. If you find any, introduce a new variable.
Code
Sample Code
Scanner scanner = new Scanner(System.in);
int how = Integer.parseInt(scanner.nextLine());
int tol = 0;
int hr = 0;
boolean toe = false;
for (int ch = 1; ch <= how; ch++) {
hr = ch;
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Hints
Reduce the span of the variables by declaring them at the moment they receive a value, not before
Rename your variables to represent their real purpose (example: "toe" should become isSpecialNum, etc.)
Search for variables that have multiple purposes. If you find any, introduce a new variable
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.