fork download
  1. /**
  2.  *
  3.  * @author Damien Bell <SkyeShatter@gmail.com>
  4.  */
  5. import java.lang.Math;
  6. import java.util.Scanner;
  7. class Jtutorial1 {
  8. public static void main(String args[]){
  9. Scanner input = new Scanner(System.in);
  10. // Declare a double, run some tests on it.
  11. // Is it even or odd? Is it a perfect square? Is it a whole number?
  12. // Is the number squared even?
  13.  
  14.  
  15. double choice=0;
  16.  
  17. System.out.println("Enter a value for the variable: ");
  18. choice = input.nextDouble();
  19.  
  20. //even
  21. if((choice%2) < 1){
  22. System.out.println("The number " + choice + " is even prior to the decimal point. ");
  23. }
  24. else{
  25. System.out.println("The number " + choice + " is NOT even. ");
  26. }
  27.  
  28. //perfect square
  29. if(((Math.sqrt(choice))%1) == 0){//sqrt(9) == 3
  30. System.out.println("The number " + choice + " is a perfect square: " + Math.sqrt(choice));
  31. }
  32. else{
  33. System.out.println("The number " + choice + " is NOT a perfect square: " + Math.sqrt(choice));
  34. }
  35.  
  36. if ((choice%1) == 0){
  37. System.out.println("The number " + choice + " is a whole number: ");
  38. }
  39. else {
  40. System.out.println("The number " + choice + " is NOT a whole number: ");
  41. }
  42.  
  43. if((((Math.pow(choice, 2)))%2) == 0){
  44. System.out.println("The number " + choice + " squared is even: "+ Math.pow(choice, 2));
  45. }
  46. else{
  47. System.out.println("The number " + choice + " squared is NOT even: " + Math.pow(choice, 2));
  48. }
  49.  
  50. } //End main
  51. } //End class
  52.  
Success #stdin #stdout 0.07s 213440KB
stdin
9
stdout
Enter a value for the variable: 
The number 9.0 is NOT even. 
The number 9.0  is a perfect square: 3.0
The number 9.0 is a whole number: 
The number 9.0 squared is NOT even: 81.0