企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Java 程序:在给定范围之间打印 Armstrong 数字 > 原文: [https://beginnersbook.com/2019/02/java-program-to-print-armstrong-numbers-between-a-given-range/](https://beginnersbook.com/2019/02/java-program-to-print-armstrong-numbers-between-a-given-range/) 我们已经看过 java [程序来检查 Armstrong 数字](https://beginnersbook.com/2017/09/java-program-to-check-armstrong-number/)。在本教程中,我们将编写一个 java 程序来打印给定范围之间的 Armstrong 数字。 ## Java 示例:在给定范围之间打印 Armstrong 数字 在此程序中,要求用户输入起始和结束数字,程序然后在这些[输入数字](https://beginnersbook.com/2014/07/java-program-to-get-input-from-user/)之间打印 Armstrong 数字。 ```java package com.beginnersbook; import java.util.Scanner; public class JavaExample { public static void main(String args[]) { int num, start, end, i, rem, temp, counter=0; Scanner scanner = new Scanner(System.in); System.out.print("Enter the start number: "); start = scanner.nextInt(); System.out.print("Enter the end number: "); end = scanner.nextInt(); scanner.close(); //generate Armstrong numbers between start and end for(i=start+1; i<end; i++) { temp = i; num = 0; while(temp != 0) { rem = temp%10; num = num + rem*rem*rem; temp = temp/10; } if(i == num) { if(counter == 0) { System.out.print("Armstrong Numbers Between "+start+" and "+end+": "); } System.out.print(i + " "); counter++; } } // if no Armstrong number is found if(counter == 0) { System.out.print("There is no Armstrong number Between "+start+" and "+end); } } } ``` **输出:** ![Java program to Print Armstrong numbers between a given range](https://img.kancloud.cn/9e/c6/9ec63a3427909483c8cd5f87ce5686f8_1008x278.jpg) #### 相关的 Java 示例 1. [Java 程序:打印 Pascal 三角形](https://beginnersbook.com/2019/02/java-program-to-print-pascal-triangle/) 2. [Java 程序:将整数分解为数字](https://beginnersbook.com/2019/02/java-program-to-break-integer-into-digits/) 3. [Java 程序:打印给定范围之间的素数](https://beginnersbook.com/2014/01/java-program-to-display-prime-numbers/) 4. [Java 程序:生成随机数](https://beginnersbook.com/2014/04/java-program-to-generate-random-number-example/)