40% DISCOUNT LIMITED SEATS
Java Full Stack + AI Industrial Training 2026
Expert MNC Mentors • Industrial Roadmap • 10 Seats Left
GitHub
Month 01: Lab Setup

Java & GitHub

  • Java 21 & IntelliJ AI Mastery
  • GitHub Team Industrial Flow
  • MNC Standard VS Code Setup
Logic
Month 02: Logic Lab

Logic Mastery

  • Complex DSA with MNC Experts
  • Telugu & English Logic Bridge
  • Daily Problem Solving Drills
Backend
Month 03: API Hub

Spring & SQL

  • Spring Boot 3 Microservices
  • Postman API Automated Testing
  • PostgreSQL DB Architecture
Frontend
Month 04: UI Factory

React & Tailwind

  • React 18 & AI Component Dev
  • Industrial Tailwind UI Library
  • Redux State Management
Cloud
Month 05: Deploy

AWS & Jira Hub

  • Cloud Deploy on Real AWS
  • Agile Scrum with Jira Tools
  • Jenkins CI/CD Pipeline
Success
Month 06: Result

Job Offer Letter

  • Tier-1 MNC Direct Referrals
  • Salary Negotiation Strategy
  • High CTC Placement Pipeline

Understanding ArmStrong Numbers in Java - Explained with Code

Yogi Siddeswara 0


What Are Armstrong Numbers?

Armstrong numbers are special numbers where the sum of their individual digits, each raised to the power of the number of digits, equals the original number itself. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153.


The Java Code:

Let's break down the Java code provided:

package in.studyecart.impprograms;

import java.util.Scanner;

public class SECJAP112 {

    public static void main(String[] args) {
        
        Scanner input = new Scanner(System.in);
        System.out.println("Please Enter a Number :");
        int actual_num = input.nextInt(), sum_num = 0, current_num = actual_num, count = 0;

        // Finding the count of digits in the given number
        while (actual_num != 0) {
            actual_num = actual_num / 10;
            count++;
        }
        actual_num = current_num;

        while (actual_num != 0) {
            int digit = actual_num % 10;
            sum_num = (int) (sum_num + Math.pow(digit, count));
            actual_num = actual_num / 10;
        }

        if (current_num == sum_num) {
            System.out.println(current_num + " is Armstrong!!");
        } else {
            System.out.println(current_num + " is Not Armstrong!!");
        }
    }
}




(code-box)

Explaining the Code:

1. We start by taking input from the user, which is the number we want to check for Armstrong property.


2. We then find the count of digits in the given number using a while loop. This count will help us later in the calculation.


3. Next, we reset `actual_num` to the original number and enter another loop to calculate the sum of each digit raised to the power of the count of digits. This is where the magic happens in identifying Armstrong numbers.


4. Finally, we compare `current_num` (the original number) with `sum_num` (the calculated sum). If they are equal, we print that the number is Armstrong; otherwise, we print that it's not.


Armstrong numbers are a fun concept in mathematics and programming. This Java program allows you to determine whether a given number fits the Armstrong criteria. Try it out with different numbers and explore this fascinating mathematical property in action!

Post a Comment

0 Comments