Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int liczba;
- boolean czyPierwsza = true;
- System.out.println("Podaj dodatnią liczbę naturalną:");
- liczba = sc.nextInt();
- Interprime proba = new Interprime(liczba, czyPierwsza);//Interprime cannot be resolved to a type
- System.out.println("Czy podana liczba jest pierwsza... " + proba.sprawdz());
- class Interprime{
- int liczba;
- boolean czyPierwsza = true;
- Interprime(int liczba, boolean czyPierwsza){
- this.liczba = liczba;
- this.czyPierwsza = czyPierwsza;
- }
- boolean sprawdz(int liczba, boolean czyPierwsza){
- for(int i=2; i*i<=liczba; i++)
- if(liczba%i==0){
- czyPierwsza = false;
- }
- return czyPierwsza;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment