Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. public class Androide {
  2.  
  3.     private static int tag = 1;
  4.     private String nome;
  5.  
  6.     public Androide() {
  7.         this.nome = "Bob" + tag;
  8.         cambiaTag();
  9.     }
  10.  
  11.  
  12.     public String getNome() {
  13.         return nome;
  14.     }
  15.  
  16.     private static void cambiaTag() {
  17.         if (!isPrimo(++tag)) {
  18.             cambiaTag();
  19.         }
  20.     }
  21.  
  22.     public static boolean isPrimo(int n) {
  23.         if (n == 2 || n == 1) return true;
  24.         if (n % 2 == 0) return false;
  25.         int i = 2;
  26.         do {
  27.             if (n - i == 1) return true;
  28.             if (n % i == 0) {
  29.                 return false;
  30.             }
  31.         } while (i++ < n);
  32.         return true;
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement