This Logic of Program is simple, less coding and decrease complexity for Reverse Number.in a logic not declare statement in block of for loop,but assign value in increment part in for loop,until original value means num variable not 0.
CODING:
import java.util.Scanner;
class reverse{
public static void main(String[] args){
int num,re=0;
Scanner n=new Scanner(System.in);
System.out.print("Enter The Prime Number:");
num=n.nextInt();
for(int rm=0;num!=0;rm=num%10,num/=10,re=re*10+rm){}
System.out.print("Reversed Number : "+re);
}
}
class reverse{
public static void main(String[] args){
int num,re=0;
Scanner n=new Scanner(System.in);
System.out.print("Enter The Prime Number:");
num=n.nextInt();
for(int rm=0;num!=0;rm=num%10,num/=10,re=re*10+rm){}
System.out.print("Reversed Number : "+re);
}
}
Comments
Post a Comment