trojanxem

Untitled

Jul 18th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4.  
  5. public class liczbypierwsze {
  6.     static int NWD(int a, int b)
  7.     {
  8.         int c;
  9.         while (b != 0)
  10.         {
  11.               c = a % b;
  12.               a = b;
  13.               b = c;
  14.      
  15.         }
  16.         return a;
  17.     }
  18.    
  19.     public static void main(String[] args) {
  20.     System.out.println("Podaj pierwsza liczbe: ");
  21.     Scanner odczyt = new Scanner(System.in);
  22.     int a  = odczyt.nextInt();
  23.     System.out.println("Podaj druga liczbe: ");
  24.     int b = odczyt.nextInt();
  25.     if ( a >= 1000000 || b >=1000000 && a <= 1 || b <= 1 )
  26.     {
  27.         System.out.println("Podales za duze liczy!");
  28.        
  29.     }
  30.     else
  31.     {
  32.         System.out.println("NWD to: "+ NWD(a,b));
  33.        
  34.     }
  35.        
  36.      
  37.    
  38.        
  39.  
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment