Advertisement
desislava_topuzakova

Цифри 28.08.2016

Feb 26th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package Mentorship;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Digits {
  6.     public static void main(String[] agrs) {
  7.         Scanner scanner = new Scanner(System.in);
  8.        
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.        
  11.         int firstDigit = n / 100; //стотици
  12.         int secondDigit = (n / 10) % 10; //десетици
  13.         int thirdDigit = n % 10; //единици
  14.        
  15.         int rows = firstDigit + secondDigit;
  16.         int col = firstDigit + thirdDigit;
  17.        
  18.         for (int i = 0; i < rows; i++) {
  19.             for (int j = 0; j < col; j++) {
  20.                 if (n % 5 == 0) {
  21.                     n = n - firstDigit;
  22.                     System.out.print(n + " ");
  23.  
  24.                 } else if (n % 3 == 0) {
  25.                     n = n - secondDigit;
  26.                     System.out.print(n + " ");
  27.                 } else {
  28.                     n = n + thirdDigit;
  29.                     System.out.print(n + " ");
  30.                 }
  31.             }
  32.             System.out.println();
  33.  
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement