Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DrawBox {
- public static void main(String[] args) {
- drawBox(10, 15);
- /*
- * FORMÅL:
- * for-loops samt parametrisere printf
- * dvs at System.out.printf("%14s%n","#") bliver til
- * format = "%" + variabel + "s%n";
- * myChar = "*"
- * System.out.printf(format,myChar);
- *
- *
- * OPGAVEN:
- * tegn en firkant vha metoden drawBox hvor højde og bredde
- * angives som parametre
- *
- * TESTKØRSEL:
- * drawBox(6,10) giver flg. figur
- **********
- * *
- * *
- * *
- * *
- **********
- */
- }
- public static void drawBox(int height, int width) {
- String format = "%s%" + (width - 1) + "s%n";
- // String myEmpty = " ";
- writeChars('*', width);
- for (int i = 0; i < height - 2; i++) {
- System.out.printf(format, "*", "*");
- }
- // TODO: skriv for-loop hvor hver iteration tegner en linje
- // og hvor antallet af loops begrænses af height samt at
- // width indgår i formateringen af printf.
- // a la format = "*%"+width+"s" og så printf(format,args)
- writeChars('*', width);
- }
- public static void writeChars(char myChar, int frequency) {
- //TODO: skriv for-loopet der printer myChar det antal gange
- // der er med som anden parameter i metodekaldet
- for (int i = 0; i < frequency; i++) {
- System.out.print(myChar);
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement