Write a Java program that reads an positive integer and count the number of digits the number (less than ten billion)?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a Java program that reads an positive integer and count the number of digits the number (less than ten billion)??

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner n = new Scanner(System.in); System.out.println("input a intger less than ten billon"); long p = n.nextLong(); int count = 0; while (p != 0) { p /= 10; count++; } System.out.println("the number of sigits is " +count); // tell me is this true solution } }

30th Sep 2019, 1:30 PM
Hawaa Basheer Ali Elamin
Hawaa Basheer Ali Elamin - avatar
1 Answer
0
It looks good to me
8th Oct 2019, 3:03 AM
Gisele Nelson
Gisele Nelson - avatar