fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static boolean ehPrimo(float nr) {
  11. if (nr < 2)
  12. return false;
  13. for (float i = 2; i <= (nr / 2); i++) {
  14. if (nr % i == 0)
  15. return false;
  16. System.out.println("nr = " + nr + "\ti = " +i);
  17. }
  18. return true;
  19. }
  20.  
  21. public static void main(String[] args) {
  22. float x = 11f;
  23. if (ehPrimo(x)) // se for primo
  24. System.out.println(x + " e primo");
  25. else // se não for primo
  26. System.out.println(x + " não e primo");
  27. }
  28. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
nr = 11.0	i = 2.0
nr = 11.0	i = 3.0
nr = 11.0	i = 4.0
nr = 11.0	i = 5.0
11.0 e primo