Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package com.mycompany.jerseytutorial;
  7.  
  8. import java.util.TreeMap;
  9. import javax.ws.rs.GET;
  10. import javax.ws.rs.Path;
  11. import javax.ws.rs.PathParam;
  12. import javax.ws.rs.core.Response;
  13. /**
  14. *
  15. * @author x15585873
  16. */
  17. @Path("/users")
  18. public class Tester {
  19. @GET
  20. @Path("/{param}")
  21. public Response sayHelloWorld(@PathParam("param") int message) {
  22. String output = toRoman(message);
  23. return Response.status(200).entity(output).build();
  24. }
  25.  
  26.  
  27. private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
  28.  
  29. static {
  30. //populating tree map
  31. map.put(1000, "M");
  32. map.put(900, "CM");
  33. map.put(500, "D");
  34. map.put(400, "CD");
  35. map.put(100, "C");
  36. map.put(90, "XC");
  37. map.put(50, "L");
  38. map.put(40, "XL");
  39. map.put(10, "X");
  40. map.put(9, "IX");
  41. map.put(5, "V");
  42. map.put(4, "IV");
  43. map.put(1, "I");
  44.  
  45. }
  46. public final static String toRoman(int number) {
  47. int l = map.floorKey(number);
  48. if ( number == l ) {
  49. return map.get(number);
  50. }
  51. return map.get(l) + toRoman(number-l);
  52. }
  53. public static void main(String[] args) {
  54.  
  55. int ll = 2;
  56. System.out.println("\t =\t "+Romannumerals.toRoman(ll));
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement