Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.mycompany.jerseytutorial;
- import java.util.TreeMap;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.core.Response;
- /**
- *
- * @author x15585873
- */
- @Path("/users")
- public class Tester {
- @GET
- @Path("/{param}")
- public Response sayHelloWorld(@PathParam("param") int message) {
- String output = toRoman(message);
- return Response.status(200).entity(output).build();
- }
- private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
- static {
- //populating tree map
- map.put(1000, "M");
- map.put(900, "CM");
- map.put(500, "D");
- map.put(400, "CD");
- map.put(100, "C");
- map.put(90, "XC");
- map.put(50, "L");
- map.put(40, "XL");
- map.put(10, "X");
- map.put(9, "IX");
- map.put(5, "V");
- map.put(4, "IV");
- map.put(1, "I");
- }
- public final static String toRoman(int number) {
- int l = map.floorKey(number);
- if ( number == l ) {
- return map.get(number);
- }
- return map.get(l) + toRoman(number-l);
- }
- public static void main(String[] args) {
- int ll = 2;
- System.out.println("\t =\t "+Romannumerals.toRoman(ll));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement