This may be a stupid question, but I am learning from a book, and I noticed that many examples have a print statement inside a method other than the main one. I was wondering if that matters when you put it down, so I inserted the program I was working on when the question arose. Would it be more efficient for me to have the getArea method print a region or leave it mostly?
private static Scanner in; private static double s; private static double a; public static void main(String[] args) { in = new Scanner(System.in); DecimalFormat two = new DecimalFormat("#.##"); System.out.println("Enter the length from center to vertex: "); double r = in.nextDouble(); s = getSide(r); a = getArea(s); System.out.println("The area of a pentagon of radius "+r+" is "+two.format(a)); } public static double getSide(double radius){ double side = 2 * radius * Math.sin((Math.PI) / 5); return side; } public static double getArea(double side){ double area = (5 * Math.pow(side, 2)) / (4 * Math.tan((Math.PI) / 5)); return area; }
source share