Что не так с этой программой? Цикл выполняется только один раз?
/*. An Evens number is an integer whose digits are all even. For example 2426 is an Evens number but 3224 is not. Write a function named isEvens that returns 1 if its integer argument is an Evens number otherwise it returns 0. The function signature is int isEvens (int n) */ import java.util.Scanner; public class Evenoroddnumber { int status,n,k,evencount=0,oddcount=0,temp=0; int isEvens (int n) {System.out.println("number entered from main is"+n); if(n<0) { System.out.println("number is negative"); return 0; } else if(n>0) {System.out.println("number is positive"); temp=n%10; System.out.println("reminder is"+temp); if(temp%2==0) { System.out.println("reminder is even"+temp); evencount++; System.out.println("count even number"+evencount); n=n/10; System.out.println("number devided by 10 is"+n); } else { System.out.println("reminder is odd"+temp); oddcount++; } } if(oddcount!=0) { return 0; } else { return 1; } } public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); Evenoroddnumber e1= new Evenoroddnumber(); int x=e1.isEvens(n); } }
Что я уже пробовал:
/*. An Evens number is an integer whose digits are all even. For example 2426 is an Evens number but 3224 is not. Write a function named isEvens that returns 1 if its integer argument is an Evens number otherwise it returns 0. The function signature is int isEvens (int n) */ import java.util.Scanner; public class Evenoroddnumber { int status,n,k,evencount=0,oddcount=0,temp=0; int isEvens (int n) {System.out.println("number entered from main is"+n); if(n<0) { System.out.println("number is negative"); return 0; } else if(n>0) {System.out.println("number is positive"); temp=n%10; System.out.println("reminder is"+temp); if(temp%2==0) { System.out.println("reminder is even"+temp); evencount++; System.out.println("count even number"+evencount); n=n/10; System.out.println("number devided by 10 is"+n); } else { System.out.println("reminder is odd"+temp); oddcount++; } } if(oddcount!=0) { return 0; } else { return 1; } } public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); Evenoroddnumber e1= new Evenoroddnumber(); int x=e1.isEvens(n); } }