+ 1
logic to display reverse no in java
by using loop we use the logic but how exactly we display..❓
3 Réponses
+ 1
while (n!=0)
{
x=(x*10)+n%10;
n=n/10;
}
it extracts the last number one by one from the number and adding it to a new variable while the number is shortened everytime by removing the last digit
+ 1
you can also accept the number as string and simply print it reversely
0
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String text = scanner.nextLine();
char[] arr = text.toCharArray();
for(int i=arr.length-1;i>=0;i--)
{
System.out.println(arr[i]);
}// Just we start printing from back side
}
}