settingsAccountsettings
Menusettings

Q: Ghetto Numeral System - Java Task

+7 votes

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

Ghetto Numeral System Java

asked in Java category by user john7
edited by user golearnweb

1 Answer

+1 vote
 
Best answer

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());
    }
}
answered by user nikole
selected by user golearnweb
...