JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
25 days ago4 views
👨‍💻Programming
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter Customer ID: ");
        String id = sc.next();

        // Check whether input has exactly 6 characters
        if (id.length() != 6) {
            System.out.println("X");
            return;
        }

        String otp = "";

        for (int i = 0; i < 6; i++) {

            int digit = id.charAt(i) - '0';

            // Check for odd digit
            if (digit % 2 != 0) {
                otp = otp + (digit * digit);
            }
        }

        // If no odd digits
        if (otp.length() == 0) {
            System.out.println("X");
        }
        // If OTP has less than 4 digits
        else if (otp.length() < 4) {
            System.out.println("X");
        }
        // If OTP has exactly 4 digits
        else {
            // Print only first 4 digits
            for (int i = 0; i < 4; i++) {
                System.out.print(otp.charAt(i));
           
 }
        }

        sc.close();
    }
}

⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.

← Back to timeline