Git Product home page Git Product logo

bhaskarrepo's Introduction

bhaskarrepo

bhaskarrepo

i have run intially in remontest class and i varified the result and i got successful result.

after that i have tried for spring boot with rest controller approch

the logic as below :

import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;

import com.companyname.springbootcrudrest.exception.RomenNumeralException;

public class RomenTest {

@GetMapping("/roman-validate")
public static String RomanNumerals(int num)   
{  
LinkedHashMap<String, Integer> romanNumerals = new LinkedHashMap<String, Integer>();  
//storing roman letters and corresponding decimal values in HashMap  
romanNumerals.put("M", 1000);  
romanNumerals.put("CM", 900);  
romanNumerals.put("D", 500);  
romanNumerals.put("CD", 400);  
romanNumerals.put("C", 100);  
romanNumerals.put("XC", 90);  
romanNumerals.put("L", 50);  
romanNumerals.put("XL", 40);  
romanNumerals.put("X", 10);  
romanNumerals.put("IX", 9);  
romanNumerals.put("V", 5);  
romanNumerals.put("IV", 4);  
romanNumerals.put("I", 1);  
//variable for string the result  
String result = "";  
//loop iterate over Map  
for(Map.Entry<String, Integer> entry : romanNumerals.entrySet())  
{  
int matches = num/entry.getValue();  
result = result+repeat(entry.getKey(), matches);  
num = num % entry.getValue();  
}  
return result;  
}  
public static String repeat(String s, int n)   
{  
if(s == null)   
{  
return null;  
}  
final StringBuilder sb = new StringBuilder();  
for(int i = 0; i < n; i++)   
{  
sb.append(s);  
}  
//converts into string  
return sb.toString();  
}  
//driver code  
public static void main(String args[])   
{  
//prints roman numerals from 1 to 200 
	 Integer a[] = new Integer[] { 1, 4, 9, 90, 900, 1903, 1997, 4000, 0, -1 };
	 
     // Getting the list view of Array
     List<Object> list = Arrays.asList(a);
	
for (int i = 1;i<=list.size();i++)   
{  
	if(a[i]==0&& a[i]==-1)
	throw new RomenNumeralException("Romen numeral exception"+a[i]);
System.out.println("i="+a[i]+" -> "+RomanNumerals(a[i]));  
}  
}  

}

o/p :

i=4 -> IV i=9 -> IX i=90 -> XC i=900 -> CM i=1903 -> MCMIII i=1997 -> MCMXCVII i=4000 -> MMMM i=0 -> i=-1 -> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10 at RomenTest.main(RomenTest.java:67)

after that i have tried in rest api  define controller,service class as below:
1.RomanNumeralToDigitController

@GetMapping("/roman-validate")
public static void romenValidate()
{

rs.validateRomen();
  
	
}
2.RomenValidateService

 Integer a[] = new Integer[] { 1, 4, 9, 90, 900, 1903, 1997, 4000, 0, -1 };
 
 // Getting the list view of Array
 List<Object> list = Arrays.asList(a);
public void validateRomen() {

for (int i = 1;i<=list.size();i++)
{
if(a[i]==0&& a[i]==-1) throw new RomenNumeralException("Romen numeral exception"+a[i]); System.out.println("i="+a[i]+" -> "+RomanNumerals(a[i]));

} RomanNumerals(int ) call from service class.

bhaskarrepo's People

Contributors

bhaskararaobattula avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.