Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Zadanie1Petla {
  4.     public static void main(String[] args) {
  5.         /**
  6.          * Krok 1: Pobranie danych
  7.          */
  8.         Scanner wejscie = new Scanner(System.in);
  9.         System.out.println("podaj liczbe ");
  10.         int a = wejscie.nextInt();
  11.         System.out.println("podaj 2 liczbe");
  12.         int b = wejscie.nextInt();
  13.         System.out.println("podaj 3 liczbe");
  14.         int c = wejscie.nextInt();
  15.         /**
  16.          * Krok 2: Walidacja danych
  17.          */
  18.  
  19.         if (a == b) {
  20.             System.out.println("Błąd! Zmienna 1 i zmienna 2 powinny mieć różną wartość");
  21.             return;
  22.         }
  23.  
  24.         if (c == 0) {
  25.             System.out.println("Błąd! Zmienna 3 nie może być równa 0");
  26.             return;
  27.         }
  28.  
  29.         /**
  30.          * Krok 3: Wyznaczenie liczb podzielnych przez c
  31.          */
  32.  
  33.         if (b > a) {
  34.             for (int i = a; i <= b; i++) {
  35.                 if (i % c == 0) {
  36.                     System.out.print(i + ",");
  37.                 }
  38.             }
  39.         } else {
  40.             for (int i = b; i <= a; i++) {
  41.                 if (i % c == 0) {
  42.                     System.out.print(i + ",");
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement