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.  
  16.  
  17. double choice=0;
  18. boolean isEven=false, isPS=false, isWhole=false, isSquaredEven=false;
  19.  
  20.  
  21. System.out.println("Enter a value for the variable: ");
  22. choice = input.nextDouble();
  23.  
  24. //even
  25. if((choice%2) < 1){
  26. isEven=true;
  27. //System.out.println("The number " + choice + " is even prior to the decimal point. ");
  28. }
  29. else{
  30. isEven=false;
  31. //System.out.println("The number " + choice + " is NOT even. ");
  32. }
  33.  
  34. //perfect square
  35. if(((Math.sqrt(choice))%1) == 0){//sqrt(9) == 3
  36. isPS=true;
  37. //System.out.println("The number " + choice + " is a perfect square: " + Math.sqrt(choice));
  38. }
  39. else{
  40. isPS=false;
  41. //System.out.println("The number " + choice + " is NOT a perfect square: " + Math.sqrt(choice));
  42. }
  43.  
  44. if ((choice%1) == 0){
  45. isWhole=true;
  46. //System.out.println("The number " + choice + " is a whole number: ");
  47. }
  48. else {
  49. isWhole=false;
  50. //System.out.println("The number " + choice + " is NOT a whole number: ");
  51. }
  52.  
  53. if((((Math.pow(choice, 2)))%2) == 0){
  54. isSquaredEven=true;
  55. //System.out.println("The number " + choice + " squared is even: "+ Math.pow(choice, 2));
  56. }
  57. else{
  58. isSquaredEven=false;
  59. //System.out.println("The number " + choice + " squared is NOT even: " + Math.pow(choice, 2));
  60. }
  61.  
  62. if(isEven){
  63. System.out.println("The number is even. ");
  64. }
  65. if(isPS){
  66. System.out.println("The number is a perfect square. ");
  67. }
  68. if(isWhole){
  69. System.out.println("The number is whole. ");
  70. }
  71. if(isSquaredEven){
  72. System.out.println("The number sqared is even. ");
  73. }
  74.  
  75.  
  76.  
  77.  
  78. } //End main
  79. } //End class
  80.  
Success #stdin #stdout 0.08s 213440KB
stdin
16
stdout
Enter a value for the variable: 
The number is even. 
The number is a perfect square. 
The number is whole. 
The number sqared is even.