Skip to content

Commit f606e8a

Browse files
authored
By these three was the third part of men killed
By these three was the third part of men killed, by the fire, and by the smoke, and by the brimstone, which issued out of their mouths (Revelation 9:18)
1 parent 1fcc972 commit f606e8a

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
//By these three was the third part of men killed, by the fire, and by the smoke, and by the brimstone, which issued out of their mouths (Revelation 9:18)
3+
4+
package com.javarush.task.task30.task3002;
5+
6+
/*
7+
Осваиваем методы класса Integer
8+
*/
9+
public class Solution {
10+
11+
public static void main(String[] args) {
12+
System.out.println(convertToDecimalSystem("0x16")); //22
13+
System.out.println(convertToDecimalSystem("012")); //10
14+
System.out.println(convertToDecimalSystem("0b10")); //2
15+
System.out.println(convertToDecimalSystem("62")); //62
16+
}
17+
18+
public static String convertToDecimalSystem(String s) {
19+
int result = 0; //напишите тут ваш код
20+
if (!s.startsWith("0")) return s;
21+
else {
22+
if (s.startsWith("0x")) result = Integer.parseInt(s.substring(2), 16);
23+
else {
24+
if (s.startsWith("0b")) result = Integer.parseInt(s.substring(2), 2);
25+
else {
26+
if (s.startsWith("0")) result = Integer.parseInt(s, 8);
27+
}
28+
}
29+
}
30+
return String.valueOf(result);
31+
}
32+
}
33+
34+
/*
35+
Осваиваем методы класса Integer
36+
37+
Используя метод Integer.parseInt(String, int) реализуй логику метода convertToDecimalSystem, который должен переводить переданную строку в десятичное число и возвращать его в виде строки.
38+
39+
40+
41+
42+
43+
Требования:
44+
45+
1. В классе Solution должен существовать метод convertToDecimalSystem(String), возвращающий String.
46+
47+
2. Метод convertToDecimalSystem(String) должен иметь модификаторы доступа: public, static.
48+
49+
3. Метод convertToDecimalSystem(String) должен вызывать метод Integer.parseInt(String, int).
50+
51+
4. Метод convertToDecimalSystem(String) должен переводить переданную строку в десятичное число и возвращать его в виде строки.
52+
*/

0 commit comments

Comments
 (0)