Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- squareRootSum();
- }
- public static int squareRootSum() {
- int sum = 0;
- BigDecimal root;
- MathContext wtf = new MathContext(101, RoundingMode.HALF_UP);
- BigDecimal number = BigDecimal.ONE;
- for (int i = 1; i <= 100; i++) {
- if (Math.sqrt(i) != (int) Math.sqrt(i)) {
- System.out.println(i);
- root = number.sqrt(wtf);
- String digits = root.toString();
- StringBuffer copy = new StringBuffer(digits).deleteCharAt(1);
- System.out.println(copy);
- copy.deleteCharAt(copy.length() - 1);
- for (int j = 0; j < copy.length(); j++) {
- sum = sum + Character.getNumericValue(copy.charAt(j));
- }
- System.out.println("sum: " + sum + "; length: " + copy.length());
- }
- number = number.add(BigDecimal.ONE);
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement