Guest User

Untitled

a guest
Oct 17th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.          Scanner sc = new Scanner(System.in);
  7.          
  8.          int liczba;
  9.          boolean czyPierwsza = true;
  10.      
  11.     System.out.println("Podaj dodatnią liczbę naturalną:");
  12.         liczba = sc.nextInt();
  13.    
  14.     Interprime proba = new Interprime(liczba, czyPierwsza);//Interprime cannot be resolved to a type  
  15.     System.out.println("Czy podana liczba jest pierwsza... " + proba.sprawdz());
  16.            
  17. class Interprime{
  18.     int liczba;
  19.     boolean czyPierwsza = true;
  20.  
  21.     Interprime(int liczba, boolean czyPierwsza){
  22.         this.liczba = liczba;
  23.         this.czyPierwsza = czyPierwsza;
  24.     }
  25.     boolean sprawdz(int liczba, boolean czyPierwsza){
  26.            
  27.         for(int i=2; i*i<=liczba; i++)
  28.             if(liczba%i==0){
  29.                 czyPierwsza = false;
  30.             }
  31.         return czyPierwsza;
  32.         }
  33.     }                      
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment