Problem:
Write a program that reads an integer N followed by N positive integers. For each entered integer, your program prints (on a new line) its digits in reverse.
Output:
3
35423
7
98710789
3
32453
7
98701789
35423
7
98710789
3
32453
7
98701789
Solution:
import java.util.Scanner;
public class lauprob6
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
int x= 1;
while (x == 1)
{
int digit = scan.nextInt();
String str = Integer.toString(digit);
for (int count = str.length() - 1; count >=0;count--)
System.out.print(str.charAt(count));
System.out.println();
}
}
}
No comments :
Post a Comment