import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i, j, n, m, a, b, c;
while (sc.hasNextInt()) {
m = sc.nextInt();
n = sc.nextInt();
for (i = m, j = 0; i <= n; i++) {
a = i / 100;
b = i / 10 % 10;
c = i % 10;
if (a * a * a + b * b * b + c * c * c == i) {
if (j > 0) {
System.out.print(" " + i);
} else {
System.out.print(i);
}
j++;
}
}
if (j == 0) {
System.out.print("no");
}
System.out.println();
}
}
}
第二段:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int start, end;
int[] results = new int[10];
while (sc.hasNext()) {
start = sc.nextInt();
end = sc.nextInt();
int counter = 0;
for (int i = start; i < end + 1; i++) {
if(isSpecial(i)) {
// 將結果先放在陣列中,方便控制輸出和換行
results[counter] = i;
counter++;
}
}
if(results[0] == 0) {
System.out.println("no");
} else {
for (int i = 0; i < counter; i++) {
if(i == 0) {
System.out.print(results[i]);
} else {
System.out.print(" "+results[i]);
}
/*if(i == counter-1) {
// 最后一個結果換行
System.out.println(results[i]);
} else {
System.out.print(results[i]+" ");
}*/
}
System.out.println();
}
}
}
private static boolean isSpecial(int n) {
int a, b, c;
// 個位
a = n%10;
// 十位
b = (n/10)%10;
// 百位
c = (n/100);
return (a*a*a + b*b*b + c*c*c) == n;
}
}
眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......
值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......