小编buc*_*ky1的帖子

Java | int方法| 我需要ELSE {Return nothing}

我遇到过一种情况,我需要使用一种方法来检查10到50之间的数字的两位数之和是否大于10,然后显示该数字.我必须使用for循环.

这是我的主要内容:

public class nested_loop2 
{ 
public static void main(String args[])  
{ 
    for (int i=10;i<=50;i++){
       System.out.println(ax(i));       
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的方法:

   public static int ax(int i){
       int a=i/10;
       int b=i%10;
       if((a+b)>10){
           return i; 
       }
       else { 
          return 0;
       }
    }
 }
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是我希望它只显示那些通过验证的特定数字.在当前状态下,它还会为所有不适合的打印出0.我不希望它返回0,我只是希望它不返回else {}语句的任何内容.

java methods if-statement return

1
推荐指数
1
解决办法
2779
查看次数

标签 统计

if-statement ×1

java ×1

methods ×1

return ×1