Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4. squareRootSum();
  5. }
  6.  
  7. public static int squareRootSum() {
  8. int sum = 0;
  9. BigDecimal root;
  10. MathContext wtf = new MathContext(101, RoundingMode.HALF_UP);
  11. BigDecimal number = BigDecimal.ONE;
  12.  
  13. for (int i = 1; i <= 100; i++) {
  14.  
  15. if (Math.sqrt(i) != (int) Math.sqrt(i)) {
  16. System.out.println(i);
  17. root = number.sqrt(wtf);
  18. String digits = root.toString();
  19. StringBuffer copy = new StringBuffer(digits).deleteCharAt(1);
  20. System.out.println(copy);
  21.  
  22. copy.deleteCharAt(copy.length() - 1);
  23. for (int j = 0; j < copy.length(); j++) {
  24. sum = sum + Character.getNumericValue(copy.charAt(j));
  25. }
  26.  
  27. System.out.println("sum: " + sum + "; length: " + copy.length());
  28.  
  29. }
  30. number = number.add(BigDecimal.ONE);
  31.  
  32. }
  33. return sum;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement