#给牛客的问题反馈和建议# 提交运行通过不了的测试用例,自测却可以通过
题目是字节跳动编程真题ZJ17水仙花数
```
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
int m = scan.nextInt();
int n = scan.nextInt();
StringBuffer sb = new StringBuffer();
while(m <= n){
if(isShuiXianHua(m)){
sb.append(m+" ");
}
m++;
}
String res = sb.toString();
if(res == null){
System.out.println("no");
}else{
System.out.println(res);
}
}
public static boolean isShuiXianHua(int m){
if((m/100)<1 || (m/100)>9){
return false;
}
int a = m/100;
int b = (m%100)/10;
int c = m%10;
int tmp = (int)Math.pow(a,3) + (int)Math.pow(b,3) + (int)Math.pow(c,3);
if(tmp == m){
return true;
}
return false;
}
}
```
题目是字节跳动编程真题ZJ17水仙花数
```
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
int m = scan.nextInt();
int n = scan.nextInt();
StringBuffer sb = new StringBuffer();
while(m <= n){
if(isShuiXianHua(m)){
sb.append(m+" ");
}
m++;
}
String res = sb.toString();
if(res == null){
System.out.println("no");
}else{
System.out.println(res);
}
}
public static boolean isShuiXianHua(int m){
if((m/100)<1 || (m/100)>9){
return false;
}
int a = m/100;
int b = (m%100)/10;
int c = m%10;
int tmp = (int)Math.pow(a,3) + (int)Math.pow(b,3) + (int)Math.pow(c,3);
if(tmp == m){
return true;
}
return false;
}
}
```
全部评论
相关推荐
点赞 评论 收藏
分享
2024-12-10 05:47
天津外国语大学 Java 点赞 评论 收藏
分享
2024-12-24 21:25
合肥工业大学 Java 点赞 评论 收藏
分享