Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. package midterm;
  3.  
  4. public class test2 {
  5. public static void main(String[] args) {
  6. drawPlusVersion();
  7. drawPlusVersion2(5);
  8. drawPlusVersion3(11);
  9. theBiggest(3,10,21);
  10. printTheBiggest(3, 10, 21);
  11. }
  12.  
  13. public static void drawPlusVersion() {
  14. final int HALF_ROW = 5;
  15. for (int i = 0; i < HALF_ROW; i++) {
  16. System.out.print(" *\n");
  17. }
  18. System.out.println("* * * * * * * * * * *" + "");
  19. for (int i = 0; i < HALF_ROW; i++) {
  20. System.out.print(" *\n");
  21. }
  22. }
  23.  
  24. /**
  25. *@param int stars
  26. **/
  27. public static void drawPlusVersion2(int stars) {
  28. if (stars % 2 != 0) { //Check if number is odd
  29. for (int y = 0; y < stars; y++) {
  30. for (int x = 0; x < stars; x++) {
  31. if (x == (int) (stars / 2) || y == (int) (stars / 2)) {
  32. System.out.print("* ");
  33. } else {
  34. System.out.print(" ");
  35. }
  36. }
  37. System.out.println();
  38. }
  39. } else { // If even number, print message
  40. System.out.println("Odd number required");
  41. }
  42. }
  43.  
  44. public static void drawPlusVersion3(int stars) {
  45. if (stars % 2 != 0) { //Check if number is odd
  46. for (int y = 0; y < stars; y++) {
  47. for (int x = 0; x < stars; x++) {
  48. if (x == (int) (stars / 2) || y == (int) (stars / 2) || x==y) {
  49. System.out.print("* ");
  50. } else {
  51. System.out.print(" ");
  52. }
  53. }
  54. System.out.println();
  55. }
  56. } else { // If even number, print message
  57. System.out.println("Odd number required");
  58. }
  59. }
  60. /**
  61. *@param int a, b ,c
  62. *@return maximum
  63. **/
  64. public static int theBiggest(int a, int b, int c) {
  65. int maximum = 0;
  66. int value = 0;
  67. if (a > 0 && b > 0 && c > 0){
  68. for (int i = 1; i <= 3; i++) {
  69. if (i == 1)
  70. value = a;
  71. if (i == 2)
  72. value = b;
  73. if (i == 3)
  74. value = c;
  75. if (value > maximum)
  76. maximum = value;}
  77. } else { // Exit if input is negative
  78. System.exit(-1);
  79. }
  80. return maximum;
  81. }
  82.  
  83. /**
  84. *@param int a, b ,c
  85. **/
  86. public static void printTheBiggest(int a, int b, int c) {
  87. int biggestNumber = theBiggest(a, b, c);
  88. System.out.println("The biggest number is: " + biggestNumber);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement