3
28/10/2024 7:12 pm
Topic starter
Write a program that converts the decimal number system to the ghetto numeral system.
In the ghetto, numbers are represented as following:
- 0 – Gee
- 1 – Bro
- 2 – Zuz
- 3 – Ma
- 4 – Duh
- 5 - Yo
- 6 – Dis
- 7 – Hood
- 8 – Jam
- 9 – Mack
1 Answer
2
28/10/2024 7:13 pm
You must use arrays for this task:
import java.util.Scanner; public class GhettoNumeralSystem07 { public static void main(String[] args) { Scanner console = new Scanner(System.in); char[] input = console.nextLine().toCharArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length; i++) { if (input[i] == '0') { sb.append("Gee"); } else if (input[i] == '1') { sb.append("Bro"); } else if (input[i] == '2') { sb.append("Zuz"); } else if (input[i] == '3') { sb.append("Ma"); } else if (input[i] == '4') { sb.append("Duh"); } else if (input[i] == '5') { sb.append("Yo"); } else if (input[i] == '6') { sb.append("Dis"); } else if (input[i] == '7') { sb.append("Hood"); } else if (input[i] == '8') { sb.append("Jam"); } else if (input[i] == '9') { sb.append("Mack"); } } System.out.println(sb.toString()); } }