Round numbers to whole number without using the Math.round

Question:
How to round decimals to whole number, without using the Math.round or ceiling program?

Answer:
You can do it with casting.

Code:
import java.util.Scanner; 
 
public class Rounding {
   public static void main(String[] args) {
 
      Scanner scan = new Scanner(System.in);
 
      System.out.print("Enter double: " );
      Double d = scan.nextDouble();
      System.out.println("You entered: " + d);
      Integer i = d.intValue();
 
      if ( d - i >= .5 ) {
        i=i+1;
      }
 
      System.out.println("Rounded: " + i);
 
   }
}

Output:
$ java Rounding
Enter double: 12.4999
You entered: 12.4999
Rounded: 12


$ java Rounding
Enter double: 8.5
You entered: 8.5
Rounded: 9

Validating an input is a number and is greater then 99.

Question:
Design an algorithm that prompts the user to enter a number that is greater than 99 and validates the input.

Code:
import java.util.*;
 
public class ReadInt {
 
   public static void main(String[] args) {
 
      Scanner sc = new Scanner(System.in);
      int i=0;
 
      try {
 
         System.out.print("Enter Integer: ");
         i = sc.nextInt();
         System.out.println("You entered: " + i);
 
         if(i > 99){
            System.out.println(i + " is greater than 99");
         } else {
            System.out.println(i + " is NOT greater than 99");
         }
 
      } catch (InputMismatchException e) {
         System.out.println("You did not enter a number.");
      }
 
   }
}

Output:
$ java ReadInt
Enter Integer: 55
You entered: 55
55 is NOT greater than 99

$ java ReadInt
Enter Integer: 100
You entered: 100
100 is greater than 99

$ java ReadInt
Enter Integer: foo
You did not enter a number.

A java program to find the sum of squares.

Question:
A java program to find the sum of squares.

Code:
import java.util.Scanner;
 
public class SumOfSquares {
 
   public static void main(String[] args) {
 
      Scanner sc = new Scanner(System.in);
 
      System.out.print("Enter Integer: ");
      int n = sc.nextInt();
      System.out.println("You entered: " + n);
 
      int sum = 1;
 
      for (int x=2;x<=n;x++) {
        sum = sum + (x*x);
      }
      System.out.println(sum);
 
   }
}

Output:
$ java SumOfSquares
Enter Integer: 5
You entered: 5
55