Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package midterm;
  2.  
  3. public class test2 {
  4. public static void main(String[] args) {
  5. drawPlusVersion();
  6. drawPlusVersion2(5);
  7. theBiggest(3,10,21);
  8. printTheBiggest(3, 10, 21);
  9. }
  10.  
  11. public static void drawPlusVersion() {
  12. final int HALF_ROW = 5;
  13. for (int i = 0; i < HALF_ROW; i++) {
  14. System.out.print(" *\n");
  15. }
  16. System.out.println("* * * * * * * * * * *" + "");
  17. for (int i = 0; i < HALF_ROW; i++) {
  18. System.out.print(" *\n");
  19. }
  20.  
  21. }
  22.  
  23. public static void drawPlusVersion2(int stars) {
  24. if (stars % 2 != 0) {
  25. for (int y = 0; y < stars; y++) {
  26. for (int x = 0; x < stars; x++) {
  27. if (x == (int) (stars / 2) || y == (int) (stars / 2)) {
  28. System.out.print("* ");
  29. } else {
  30. System.out.print(" ");
  31. }
  32. }
  33. System.out.println();
  34. }
  35. } else {
  36. System.out.println("Odd number required");
  37. }
  38. }
  39.  
  40. public static int theBiggest(int x, int y, int z) {
  41. int max = 0;
  42. int currentNum = 0;
  43.  
  44. for (int i = 1; i <= 3; i++) {
  45. if (i == 1)
  46. currentNum = x;
  47. if (i == 2)
  48. currentNum = y;
  49. if (i == 3)
  50. currentNum = z;
  51.  
  52. if (currentNum > max)
  53. max = currentNum;
  54. }
  55.  
  56. return max;
  57. }
  58.  
  59.  
  60. public static void printTheBiggest(int x, int y, int z) {
  61. int biggestnumber = theBiggest(x, y, z);
  62. System.out.println("The biggest number is: " + biggestnumber);
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement