Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package midterm;
- public class test2 {
- public static void main(String[] args) {
- drawPlusVersion();
- drawPlusVersion2(5);
- drawPlusVersion3(11);
- theBiggest(3,10,21);
- printTheBiggest(3, 10, 21);
- }
- public static void drawPlusVersion() {
- final int HALF_ROW = 5;
- for (int i = 0; i < HALF_ROW; i++) {
- System.out.print(" *\n");
- }
- System.out.println("* * * * * * * * * * *" + "");
- for (int i = 0; i < HALF_ROW; i++) {
- System.out.print(" *\n");
- }
- }
- /**
- *@param int stars
- **/
- public static void drawPlusVersion2(int stars) {
- if (stars % 2 != 0) { //Check if number is odd
- for (int y = 0; y < stars; y++) {
- for (int x = 0; x < stars; x++) {
- if (x == (int) (stars / 2) || y == (int) (stars / 2)) {
- System.out.print("* ");
- } else {
- System.out.print(" ");
- }
- }
- System.out.println();
- }
- } else { // If even number, print message
- System.out.println("Odd number required");
- }
- }
- public static void drawPlusVersion3(int stars) {
- if (stars % 2 != 0) { //Check if number is odd
- for (int y = 0; y < stars; y++) {
- for (int x = 0; x < stars; x++) {
- if (x == (int) (stars / 2) || y == (int) (stars / 2) || x==y) {
- System.out.print("* ");
- } else {
- System.out.print(" ");
- }
- }
- System.out.println();
- }
- } else { // If even number, print message
- System.out.println("Odd number required");
- }
- }
- /**
- *@param int a, b ,c
- *@return maximum
- **/
- public static int theBiggest(int a, int b, int c) {
- int maximum = 0;
- int value = 0;
- if (a > 0 && b > 0 && c > 0){
- for (int i = 1; i <= 3; i++) {
- if (i == 1)
- value = a;
- if (i == 2)
- value = b;
- if (i == 3)
- value = c;
- if (value > maximum)
- maximum = value;}
- } else { // Exit if input is negative
- System.exit(-1);
- }
- return maximum;
- }
- /**
- *@param int a, b ,c
- **/
- public static void printTheBiggest(int a, int b, int c) {
- int biggestNumber = theBiggest(a, b, c);
- System.out.println("The biggest number is: " + biggestNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement