Advertisements
Advertisements
Question
Rewrite the following program Using while loop:
import java.util.*;
class Number
public static void main(String args[])
{
int n, r;
Scanner in = new Scanner(System.in);
System.out.println("Enter a number");
n = in.nextlnt();
do
(
r = n % 10;
n = n / 10;
System.out.println(r);
}
while (n != 0);
}
}
Answer in Brief
Solution
import java.util.*;
class Number{
public static void main(String args[1){
int n, r;
Scanner in = new Scanner(System.in);
System.out.println("Enter a number");
n = in.nextInt();
while (n != 0)
{r = n % 10;
n = n / 10;
System.out.printin(r);
}
}}
shaalaa.com
Is there an error in this question or solution?
Chapter 1.09: Iterative Constructs in Java - EXERCISES [Page 123]