Originally Posted by
andreas90
Hello Rafal75!
If you want to use Size in multiple methods you can declare it in the same level with the methods (in other words inside the class but outside the methods) - be careful with static fields and methods. And also you should better start your variable name with lower case by convention.
since it appears you are not modifing the variable inside your methods you could also simply pass it to each of your methods
eg:
import java.util.*;
public class Question2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter the size of diamond you want to print out: ");
int size = keyboard.nextInt();
line(size);
drawtop(size);
middleline(size);
drawbtm(size);
line(size);
}
public static void line(int size) {
System.out.print("|");
for (int i = 1; i <= size / 2; i++) {
System.out.print("-");
}
System.out.print("*");
for (int i = 1; i <= size / 2; i++) {
System.out.print("-");
}
System.out.print("|");
System.out.println(" ");
}