KEMBAR78
Roman To Integer | PDF
0% found this document useful (0 votes)
19 views2 pages

Roman To Integer

Uploaded by

madnani.khushi46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Roman To Integer

Uploaded by

madnani.khushi46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Roman to Integer:

import java.util.*;

public class RomantoInteger

int integer(char ch)

if(ch=='I')

return 1;

else if(ch=='V')

return 5;

else if(ch=='X')

return 10;

else if(ch=='L')

return 50;

else if(ch=='C')

return 100;

else if(ch=='D')

return 500;

else if(ch=='M')

return 1000;

else

return -1;

void main()

Scanner in = new Scanner(System.in);

System.out.println("Enter integer number");

String r=in.nextLine();

int integ=0;

for(int i=0;i<r.length();i++)
{

char ch=r.charAt(i);

char ch1='\u0000';

if(i<r.length()-1)

{ ch1=r.charAt(i+1);}

if((integer(ch))<(integer(ch1)))

integ+=(integer(ch1)-(integer(ch)));

i++;

else

integ+=(integer(ch));

System.out.print(integ);

You might also like