Page 430 - Computer science 868 Class 12
P. 430
50,40,10,9,5,4,1};
Roman()
{ n=0;
rom="";
}
void accept() // enter number
{ Scanner sc=new Scanner(System.in);
do{
System.out.println("Enter number");
n=sc.nextInt();
if(n<1 || n>4000)
System.out.println("Number not in range");
}while(n<1 || n>4000);
}
String convert(int num,int i)
{ int x;
if(i==v.length) // base case
return rom;
else
{
x=num/v[i];
if(x==1) // for single value
{ rom=rom+r[i];
}
else if(x>1)
{ for(int j=1;j<=x;j++) // for repeating values
{ rom=rom+r[i];}
}
else{}
num=num-v[i]*x;
return convert(num,i+1); // recursive case
}}
void display() // print result
{ String rm=convert(n,0);
System.out.println("Number "+n+" Roman equivalent "+rm);
}
public static void main()
{ Roman ob=new Roman();
ob.accept();
ob.display();
}}
5. Design a class Modify to search for a particular value in an array and replace it with new value. Some of the members of the class
are given below:
Data member/Instance variables
arr[] : To store integer numbers
size : Integer to store size of array
Member Methods
Modify(int s) : constructor to initialise size and declare array
428428 Touchpad Computer Science-XII

