What do the methods do in this Java program? -
i'm confused methods exactly, hoping explain concept me example program:
import java.io.*; import java.util.*; public class programb { public static void main(string[] args) throws ioexception { string filename; string total=""; string c = ""; string size = ""; int num1=0, num2=0; char ch; scanner keyboard = new scanner(system.in); system.out.println("enter name of file want read data from:"); filename=keyboard.next(); scanner fromfile = new scanner(new filereader(filename)); while (fromfile.hasnext()) { string type = fromfile.next(); ch = fromfile.next().charat(0); num1 = fromfile.nextint(); if (type.equals("rectangle")) { num2 = fromfile.nextint(); } system.out.print(type + " "); system.out.print(ch + " "); system.out.print(num1 + " "); if (type.equals("rectangle")) { system.out.print(num2); } system.out.println(); if (type.equals("rectangle")){ rectangle(ch,num1,num2); } if (type.equals("triangle")){ triangle(ch, num1); } } } /** draw rectangle of specified width , height @param c character creates drawing @param height height of rectangle @param width width of rectangle */ public static void rectangle(char c, int height, int width){ (int i=1; i<=height; i++) { system.out.println(); (int a=1; a<= width; a++) { system.out.print(c); } } system.out.println(); // put statements here display rectangle on screen using // character c , width , height parameters } /** draw right triangle. @param c character creates drawing @param size height , width of triangle */ public static void triangle(char c, int size){ (int i=1; i<=size;i++) { (int j=1; j<=i; j++) { system.out.print(c); } system.out.println(); // put statements here display triangle on screen using // character c , size parameter } } }
what methods , do? i've tried researching online , i've been studying textbook i'm still confused concept.
the documentation accompanies methods decent job of explaining do, think. rectangle()
method, when called parameters '-', 3, , 4, "draw" rectangle 3 dashes high , 4 wide in console program run:
---- ---- ----
the triangle()
method similar; when called '-' , 3, you'll shape this:
- -- ---
Comments
Post a Comment