Exercise #1
Example #1 given an int of 1200
Return value: 4
Example #2 given an int of -1200
Return value: 4
Example #3 given an int of -359
Return value: 3
In java program
//DigitCount.java import java.util.Scanner; public class DigitCount { static int extractdigitcount(int n){ int count = 0; if(n<0){ n = -1 * n; } while(n>0){ count++; n = n/10; } return count; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n; System.out.print("Enter an integer: "); n = scanner.nextInt(); System.out.println(extractdigitcount(n)); } }
Get Answers For Free
Most questions answered within 1 hours.