How to add a new method called numberOfDigits() in java?

前端 未结 4 1064
面向向阳花
面向向阳花 2021-01-29 04:19

I have a program called public class ZeroCounter {. I want to add a new method to it called numberOfDigits() and add a line to test it in the main() method. How should I go abo

4条回答
  •  一向
    一向 (楼主)
    2021-01-29 04:46

    public class ZeroCounter   {
      public static void main(String[] args) {
             System.out.println("Enter a nonnegative number:");
             Scanner keyboard = new Scanner(System.in);
             int number = keyboard.nextInt( ) ;
    
             System.out.println(number + " contains " + numberOfZeros(number) + " zeros.");
      } // End of main
    
      private static int numberOfZeros(int number) {
             int result = ///// calculation
             return result;
      }
    }
    

    You might want to read up a bit more on Java and how classes, methods and functions work first before going any further however.

提交回复
热议问题