Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
4
Indexable
import java.util.Scanner;

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

        System.out.print("Enter the value of N: ");
        int N = scanner.nextInt();

        if (N <= 0) {
            System.out.println("Invalid Input");
            return;
        }

        int oddNumber = 0;
        int evenNumber = 0;

        for (int i = 0; i < N; i++) {
            System.out.print("Enter number " + (i + 1) + ": ");
            int num = scanner.nextInt();

            while (num > 0) {
                int digit = num % 10;
                if (digit != 0) {
                    if (digit % 2 == 0) {
                        evenNumber = evenNumber * 10 + digit;
                    } else {
                        oddNumber = oddNumber * 10 + digit;
                    }
                }
                num /= 10;
            }
        }

        System.out.println("First Number: " + oddNumber);
        System.out.println("Second Number: " + evenNumber);

        scanner.close();
    }
}