Drewyboyo Posted January 23, 2017 Posted January 23, 2017 How many ways can you write something to loop? We're writing a fixed repetition for graphics like, int k;for (k = 1; k <=10; k++) Any cleaner ways to write this? Or something less monotonous?
Eagle Scripts Posted January 23, 2017 Posted January 23, 2017 Instead of declaring k above it, you could actually declare it in the loop itself as: for(int i = 0; i <= 10; i++){ // do stuff } 1
Drewyboyo Posted January 23, 2017 Author Posted January 23, 2017 for (int k = 0; k < 10; K++) isnt that exactly whats in my spoiler can't there be some silly "loop x" function Instead of declaring k above it, you could actually declare it in the loop itself as: for(int i = 0; i <= 10; i++){ // do stuff } thank ya
Solution Posted January 23, 2017 Posted January 23, 2017 isnt that exactly whats in my spoiler can't there be some silly "loop x" function thank ya Nah you can create the int inside the for condition instead of above, same difference tho. a for loop is a loop x for (int index = 0; index < 10; index++) { //do stuff } Will loop 10 times. 1
Hayase Posted January 23, 2017 Posted January 23, 2017 (edited) Who needs loops wen u can just switch it up int k= getWCExp(); //get ur wc exp cuz u need it switch (k) { case 1: checkWCexp();break; case 2: checkWCexp();break; case 3: checkWCexp();break; case 4: checkWCexp();break; case 5: checkWCexp();break; case 6: checkWCexp();break; case 7: checkWCexp();break; case 8: checkWCexp();break; case 9: checkWCexp();break; case 10: checkWCexp();break; default: checkWCexp();break; } np Edited January 23, 2017 by Hayase 1
Drewyboyo Posted January 23, 2017 Author Posted January 23, 2017 import java.awt.*;import java.applet.*;public class Lab07Bst extends Applet{public void paint(Graphics g){// Draw GridExpo.drawLine(g,250,0,250,650);Expo.drawLine(g,500,0,500,650);Expo.drawLine(g,750,0,750,650);Expo.drawLine(g,0,325,1000,325);int x1, y1, x2, y2, x, y, r;// Draw Red Horizontal LinesExpo.setColor(g,Expo.red);x1 = 0;y1 = 5;x2 = 250;y2 = 5;for (int k = 1; k <= 32; k++){Expo.drawLine(g,x1,y1,x2,y2);y1 += 10;y2 += 10;}int x3, y3, x4, y4;// Draw Blue Vertical LinesExpo.setColor(g,Expo.blue);x3 = 255;y3 = 0;x4 = 255;y4 = 325;for (int t = 1; t <= 25; t++){Expo.drawLine(g,x3,y3,x4,y4);x3 += 10;x4 += 10;}int x5, y5;// Draw Black Diagonal DotsExpo.setColor(g,Expo.black);x5 = 510;y5 = 280;for (int u = 1; u <= 24; u++){Expo.drawPoint(g,x5,y5);x5 += 10;y5 += -10;}int x6, y6, z6;// Draw Green Concentric CirclesExpo.setColor(g,Expo.green);x6 = 887;y6 = 170;z6 = 10;for (int i = 1; i <= 12; i++){Expo.drawCircle(g,x6,y6,z6);z6 += 10;}// Draw Purple Concentric Ovalsint x7, y7, z7, h7;Expo.setColor(g,Expo.purple);x7 = 125;y7 = 480;z7 = 5;h7 = 10;for (int i = 1; i <= 20; i++){Expo.drawOval(g,x7,y7,z7,h7);z7 += 4;h7 += 6;}// Draw Pink Concentric Arcsint x8, y8, z8, h8, g8, i8;Expo.setColor(g,Expo.pink);x8 = 260;y8 = 650;z8 = 5;h8 = 15;i8 = 0;g8 = 90;for (int i2 = 1; i2 <= 19; i2++){Expo.drawArc(g,x8,y8,z8,h8,i8,g8);z8 += 12;h8 += 16;}// Draw Brown Concentric Rectangles// Draw Gold Sphere Who needs loops wen u can just switch it up int k= getWCExp(); //get ur wc exp cuz u need it (switch k) { case 1: checkWCexp();break; case 2: checkWCexp();break; case 3: checkWCexp();break; case 4: checkWCexp();break; case 5: checkWCexp();break; case 6: checkWCexp();break; case 7: checkWCexp();break; case 8: checkWCexp();break; case 9: checkWCexp();break; case 10: checkWCexp();break; default: checkWCexp();break; } np
FrostBug Posted January 23, 2017 Posted January 23, 2017 If you're into this kinda stuff IntStream.range(0, 10).forEach(i -> System.out.println("Loop " + i));
Drewyboyo Posted January 23, 2017 Author Posted January 23, 2017 If you're into this kinda stuff IntStream.range(0, 10).forEach(i -> System.out.println("Loop " + i)); wheres frost godwards aio instead of replying to my starter java class help
FrostBug Posted January 23, 2017 Posted January 23, 2017 wheres frost godwards aio instead of replying to my starter java class help 4giv 1