Take 10 numbers in an array and reverse the numbers using a second function
e.g: input values 23 25 54 ……
Output would be 32 52 45……….
import java.io.*;
class Ab
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int arr[]=new int [10];
void show() throws Exception
{
int n;
for(int i=0;i<10;i++)
{
System.out.println("\nEnter Value: ");
arr[i]=Integer.parseInt(br.readLine());
}
System.out.println("\nOriginal Value");
for(int i=0;i<10;i++)
{
System.out.print(" "+arr[i]);
}
for(int i=0;i<10;i++)
{
n=arr[i];
arr[i]=reverse(n);
}
System.out.println("\nReversed Value");
for(int i=0;i<10;i++)
{
System.out.print(" "+arr[i]);
}
}
private int reverse(int n)
{
int i,r=0;
for(i=n;i>0;i=i/10)
r=r*10+i%10;
return r;
}
public static void main(String args[]) throws Exception
{
Ab obj=new Ab();
obj.show();
}
}
No comments:
Post a Comment