bishwobista / crack-code

Crack all the coding questions.
6 stars 42 forks source link

Write a Program to convert Integer to Roman in Java #96

Closed bishwobista closed 1 year ago

bishwobista commented 1 year ago

Given an integer, convert it to a roman numeral using Java language.

yasarlabib commented 1 year ago

assign it to me

bishwobista commented 1 year ago

assign it to me

sure, go ahead.

yasarlabib commented 1 year ago

Here you go!

``import java.util.Scanner;

public class IntegerToRoman { public String intToRoman(int num) { String[] thousands = {"", "M", "MM", "MMM"}; String[] hundreds = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; String[] tens = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; String[] ones = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};

    return thousands[num / 1000] + hundreds[(num % 1000) / 100] + tens[(num % 100) / 10] + ones[num % 10];
}

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    IntegerToRoman converter = new IntegerToRoman();

    System.out.print("Enter an integer: ");
    int num = scanner.nextInt();
    String romanNumeral = converter.intToRoman(num);

    System.out.println("Roman Numeral: " + romanNumeral);
}

}``

How would I merge this?

bishwobista commented 1 year ago

Here you go!

``import java.util.Scanner;

public class IntegerToRoman { public String intToRoman(int num) { String[] thousands = {"", "M", "MM", "MMM"}; String[] hundreds = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; String[] tens = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; String[] ones = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};

    return thousands[num / 1000] + hundreds[(num % 1000) / 100] + tens[(num % 100) / 10] + ones[num % 10];
}

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    IntegerToRoman converter = new IntegerToRoman();

    System.out.print("Enter an integer: ");
    int num = scanner.nextInt();
    String romanNumeral = converter.intToRoman(num);

    System.out.println("Roman Numeral: " + romanNumeral);
}

}``

How would I merge this?

You need to fork the repo -> clone it in your computer -> create a remote branch -> push the commits -> and send a Pull Request. Or just follow along a tutorial on YouTube. If there are any other issues, let me know. Good Luck ✌️

yasarlabib commented 1 year ago

Got it, thank you!!