Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level14.lesson08.bonus02;
- /* НОД
- Наибольший общий делитель (НОД).
- Ввести с клавиатуры 2 целых положительных числа.
- Вывести в консоль наибольший общий делитель.
- */
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Solution
- {
- public static void main(String[] args) throws Exception
- {
- System.out.println(NOD());
- }
- private static int NOD () throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int chislo1 = Integer.parseInt(reader.readLine());
- int chislo2 = Integer.parseInt(reader.readLine());
- int nod;
- if (chislo1>chislo2) {
- nod = chislo2;
- }
- else {
- nod = chislo1;
- }
- while (true) {
- if ((chislo1%nod == 0)&& chislo2%nod == 0) {
- break;
- }
- else
- nod--;
- }
- return nod;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement