Advertisement
cd62131

Sum Odd Digit

Dec 3rd, 2013
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.   public static void main(String[] args) {
  5.     Scanner in = new Scanner(System.in);
  6.     int n = 0;
  7.     while (n == 0) {
  8.       System.out.print("Non-Zero digit: ");
  9.       try {
  10.         n = new Integer(in.next());
  11.       }
  12.       catch (Exception e) {
  13.       }
  14.       if (n <= 0) continue;
  15.     }
  16.     in.close();
  17.     int harf;
  18.     if (n % 2 == 0) harf = n / 2;
  19.     else harf = (n + 1) / 2;
  20.     System.out.println("Result: " + harf * harf);
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement