Advertisement
Guest User

adasd

a guest
Dec 5th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package tt22hz_assign2;
  2. import java.util.Scanner;
  3.  
  4. public class Primtal {
  5.     public static void main(String[] args) {
  6.         int tal;
  7.         do {
  8.             Scanner tt = new Scanner(System.in);
  9.             System.out.print("Skriv en siffra:");
  10.             tal = tt.nextInt();
  11.             if (tomas(tal)) {
  12.                 System.out.println("Det är ett primtal.");
  13.             } else {
  14.                 System.out.println("Det är inte ett primtal.");
  15.             }
  16.  
  17.         } while (tal > -1);
  18.         System.out.println("hejdå");
  19.     }
  20.  
  21.  
  22.  
  23.     public static boolean tomas(int talen) {
  24. int tal2=0;
  25.  
  26.             if (talen >= 0) {
  27.  
  28.  
  29.             for (int i = 1; i <= talen; i =i+1) {
  30.                 if (talen % i != 0 ) {
  31.                     System.out.println("test");
  32.                     tal2 = tal2+1;
  33.                     return true;
  34.                 }
  35.  
  36.  
  37.  
  38.  
  39.             }
  40.             if ( tal2 > 2 )
  41.                 return true;
  42.             else
  43.                 return false;
  44.             }
  45.  
  46.         return false;
  47.  
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement