Advertisement
venik2405

Untitled

Sep 23rd, 2020
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3.  
  4. public class lab1_3 {
  5.     public static void main(String[] args) {
  6.         boolean isNotCorrect = false;
  7.         System.out.println("Данная программа позволяет узнать количество цифр , из которых состоит число");
  8.         int number = 1;
  9.         int colOfNumber = 1;
  10.         do {
  11.             try {
  12.                 Scanner scanner = new Scanner(System.in);
  13.                 System.out.println("Введите число");
  14.                 number = scanner.nextInt();
  15.                 if (number<9){
  16.                     isNotCorrect=true;
  17.                     System.out.println("чило должно быть больше 0");
  18.                 }
  19.             } catch (Exception e) {
  20.                 System.out.println("Введите корректное значение");
  21.                 isNotCorrect = true;
  22.             }
  23.         } while (isNotCorrect);
  24.         while (number/10>1) {
  25.                 colOfNumber = colOfNumber + 1;
  26.                 number = number / 10;
  27.         }
  28.         System.out.println("Количество цифр " +colOfNumber);
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement