Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Zadanie1Petla {
- public static void main(String[] args) {
- /**
- * Krok 1: Pobranie danych
- */
- Scanner wejscie = new Scanner(System.in);
- System.out.println("podaj liczbe ");
- int a = wejscie.nextInt();
- System.out.println("podaj 2 liczbe");
- int b = wejscie.nextInt();
- System.out.println("podaj 3 liczbe");
- int c = wejscie.nextInt();
- /**
- * Krok 2: Walidacja danych
- *
- * Tutaj powinien się znaleźć kod odpowiedzialny za sprawdzenie czy c != 0 oraz czy a!=b.
- * Jeśli dane są niepoprawne - kończymy program lub rzucamy wyjątek (zależy od treści zadania)
- * Jeśli poprawne, lecimy dalej
- */
- if (a > b) {
- System.out.println("Błąd! Zmienna 1 powinna być większa od zmiennej 2");
- }
- if (c == 0) {
- System.out.println("Błąd! Zmienna 3 nie może być równa 0");
- }
- /**
- * Krok 3: Wyznaczenie liczb podzielnych przez c
- */
- for (int i = a; i <= b; i++) {
- if (i % c == 0) {
- System.out.print(i + ",");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement