/* This program is to demostrate how methods can be built in Java. Here, we build a method that accepts an integer that represents a certain mnumber of lines. If the number of lines is even, we print an error message and exit. If the number of lines is odd, we print a triangular arrangement of *'s with those many lines. For example, if t/he number of lines is 7, we print * * * * * * * * * * * * * * * * This is a method with a void return type, as it only prints things and doesn't return any value. */ import java.util.Scanner; class Method { static void printStar(int lines) // declared static because we're calling the method without instantiating a class. { // accepts 1 integer parameter, the number of lines if(lines % 2 == 0) { // print error message if even System.out.println("Even number of lines. Can't print."); return; } // will get here only if lines is odd // This prints the top half of the triangle. for (int i=0;i<=lines/2;i++) { for(int j=0;j<=i;j++) System.out.print("* "); System.out.println(""); } // This prints the bottom half of the triangle for (int k = lines/2+1; k0;j--) System.out.print("* "); System.out.println(""); } } // main method. Can't have a standalone class without one public static void main(String [] args) { Scanner in = new Scanner(System.in); // read in the number of lines from the user System.out.print("Enter the number of lines: "); int numLines = in.nextInt(); //method call to printStar method. Pass in numLines as a parameter. printStar(numLines); } }