[英]why the swap part is executing again after the function hit return statement
[英]Why the function is executing statements even after return statement is executed?
我也檢查了調試它會聲明 =>if(sum==1) return true; 但它也在執行進一步的語句。
static long solve(int l, int r){
// Your code goes here
long sum=0;
boolean t=0;
for (int i=l;i<=r;i++) {
t=beautiful(i);
if (t==true) {
sum=sum+i;
}
}
return sum;
}
static boolean beautiful(int num) {
if (num<=0) return false;
if (num==1) return true;
int sum=0;
while (num>0) {
int rem=num%10;
sum=sum+rem*rem;
num=num/10;
}
if (sum==1) {
System.out.print("some");
return true;
}
System.out.print("one");
beautiful(sum);
return false;
}
然后你調用漂亮的方法,它進入它並得到結果並繼續。 因此,盡管您調用了beautiful方法並返回 false,您仍然可以執行此操作;
return beautiful(sum);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.