I've come across a situation where I need to use a method to check if the sum of the two digits of a number from 10 to 50 is larger than 10 and then display that number. I must use a for loop.
This is my main:
public class nested_loop2 {
public static void main(String args[]) {
for (int i=10;i<=50;i++){
System.out.println(ax(i)); }
} This is my method:
public static int ax(int i){
int a=i/10;
int b=i%10;
if((a+b)>10){ return i; }
else { return 0;}
}}
The problem I have with this is that I want it to display only those particular numbers that pass the verification. In the current state, it also prints out 0 for all the ones that didn't fit. I don't want it to return 0, I just want it to not return anything for the else{} statement.
Aucun commentaire:
Enregistrer un commentaire