0% found this document useful (0 votes)
6 views

Java1

The document contains a Java program that identifies and prints Armstrong numbers within a specified range. It includes methods to check if a number is an Armstrong number and to print all Armstrong numbers between a given start and end. The program prompts the user for input and displays the results accordingly.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java1

The document contains a Java program that identifies and prints Armstrong numbers within a specified range. It includes methods to check if a number is an Armstrong number and to print all Armstrong numbers between a given start and end. The program prompts the user for input and displays the results accordingly.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Write a java Program to print armstrong number.

import java.u l.Scanner;

public class ArmstrongNumber {

public sta c boolean isArmstrong(int number) {

int originalNumber = number;

int sum = 0;

int digits = String.valueOf(number).length();

while (number != 0) {

int digit = number % 10;

sum += Math.pow(digit, digits);

number /= 10;

return sum == originalNumber;

public sta c void printArmstrongNumbers(int start, int end) {

System.out.println("Armstrong numbers between " + start + " and " + end + " are:");

for (int i = start; i <= end; i++) {

if (isArmstrong(i)) {

System.out.print(i + " ");

public sta c void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the start of the range: ");

int start = scanner.nextInt();

System.out.print("Enter the end of the range: ");

int end = scanner.nextInt();


printArmstrongNumbers(start, end);

scanner.close();

O/P :

Enter the start of the range: 1

Enter the end of the range: 1000

Armstrong numbers between 1 and 1000 are:

1 2 3 4 5 6 7 8 9 153 370 371 407

You might also like