1) Write a program that asks the user to input an integer and the output the individual digits of the number.
2) Write a program that asks the user to input an integer and then output the number with the digits reversed.

i don't really know how to this using array. please help me!!

Hi ells912 and welcome to DaniWeb,

Both questions are very similar. You need to do the following:

1. Prompt the user for an integer.
2. Store the digits of the integer in an array.
3. Loop over the digits (Q1 in normal order, Q2 in reverse order) and print them out one by one.

We are not allowed to do this for you, but there is a breakdown of what you need to do. Give it a try and if you get stuck post some specific questions (with code to show what you've tried) and we will try to help you out.

Good luck :)
darkagn

import java.util.Scanner;


public class IntNum
{


public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);


int num, rem, condition;



System.out.print("Enter a number: ");
num = reader.nextInt();
condition = num;
int count = 0;


while (condition > 0)
{
condition  = condition / 10;
count = count + 1;
}
count = count - 1;
System.out.println("The individual digits:");
while (count >= 0)
{
rem = num % (int) Math.pow(10, count);
num = num/(int) Math.pow(10,count);
System.out.print(num + "  ");
num = rem;
// store num in array for question no. 2
count = count - 1;
// process the array for question no. 2


}

(that one is number 1 but when i run it still there's error)

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.