Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tt22hz_assign2;
- import java.util.Scanner;
- public class Primtal {
- public static void main(String[] args) {
- int tal;
- do {
- Scanner tt = new Scanner(System.in);
- System.out.print("Skriv en siffra:");
- tal = tt.nextInt();
- if (tomas(tal)) {
- System.out.println("Det är ett primtal.");
- } else {
- System.out.println("Det är inte ett primtal.");
- }
- } while (tal > -1);
- System.out.println("hejdå");
- }
- public static boolean tomas(int talen) {
- int tal2=0;
- if (talen >= 0) {
- for (int i = 1; i <= talen; i =i+1) {
- if (talen % i != 0 ) {
- System.out.println("test");
- tal2 = tal2+1;
- return true;
- }
- }
- if ( tal2 > 2 )
- return true;
- else
- return false;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement