Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Kapricoño {
  5.  
  6. static Scanner sc;
  7.  
  8. public static void main(String[] args) {
  9.  
  10. sc = new Scanner(System.in);
  11. System.out.println(isKapriCoño(sc.nextInt()) ? "Es kapricoño" : "No es kapricoño");
  12.  
  13. }
  14.  
  15. public static boolean isKapriCoño(int num) {
  16. String pow = "" + num * num;
  17.  
  18. if (num == 1) return true;
  19. for (int i = 1; i < pow.length(); i++) {
  20. int numA = Integer.parseInt(pow.substring(0, i));
  21. int numB = Integer.parseInt(pow.substring(i, pow.length()));
  22.  
  23. if (numB != 0) {
  24. if (numA + numB == num) {
  25. return true;
  26. }
  27. }
  28. }
  29. return false;
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement