//// Loop practice. int total; // int many=10; int[] list = new int[many]; float avg=0; String news=""; void setup() { size( 600, 400 ); ranlist( list, many ); avg= average( list, many ); } void draw() { background( 255,255,200 ); fill(0); // // Sum from 1 to 100. text( "Sum from 1 to 100:", 20, 20 ); total=0; int n=1; while (n<=100) { total = total + n; n = n + 1; } text( total+ " (while loop)", 20, 40 ); // // Sum from 1 to 100. total=0; for (n=1; n<101; n=n+1) { total = total + n; } text( total+ " (for loop)", 20, 60 ); // // Also show list & avg. text( "List of ten numbers:", 20, 100 ); int y=120; int k; for (k=0; k<10; k=k+1) { text( list[k], 25, y ); y = y + 20; } text( "Average: "+ avg, 20, y ); // text( "Press 'r' key to reset the list.", 30, y+30 ); text( "Press 's' key to sort the list.", 30, y+50 ); text( news, 30, y+70 ); } void keyPressed() { news=""; if (key == 'r') { ranlist( list, many ); avg= average( list, many ); } if (key == 's') { news= "Sorry! Sorting is not yet implemented"; } } void ranlist( int[] a, int many ) { // Generate a set of ten random numbers. for (int j=0; j