My teacher wants me to put a while loop into my program, where do I put it for the best outcome? public static void main(String[] args) { int min = 19; int num1=0, num2=0, num3=0; int tol1=0, tol2=0, tol3=0; int max = 50; int col[]=new int[49]; for(int i = 0; i < 49; i++){ int ran = (int)(Math.random() * (max - min + 1) + min); if( ran <= 20 && ran < 30){ num1 += 1; tol1 += ran; } if(ran <= 30 && ran < 40){ num2 += 1; tol2 += ran; } if(ran <= 40 && ran < 50){ num3 += 1; tol3 += ran; } col[i]= ran; } for(int i = 0; i < 49; i++ ){ if(i == 7 || i == 14 || i == 21 || i == 28 || i == 35 ||i == 42){ System.out.println("\n"); } System.out.printf(("%7d"),+ col[i]); } System.out.printf("\n"); System.out.printf("Found "+ num1 +" number(s) in the 20s "+ "totaling "+ tol1); System.out.printf("\nFound "+ num2 +" number(s) in the 30s "+ "totaling "+ tol2); System.out.printf("\nFound "+ num3 +" number(s) in the 40s "+ "totaling "+ tol3); } }
My teacher wants me to put a while loop into my program, where do I put it for the best outcome?
public static void main(String[] args) {
int min = 19;
int num1=0, num2=0, num3=0;
int tol1=0, tol2=0, tol3=0;
int max = 50;
int col[]=new int[49];
for(int i = 0; i < 49; i++){
int ran = (int)(Math.random() * (max - min + 1) + min);
if( ran <= 20 && ran < 30){
num1 += 1;
tol1 += ran;
}
if(ran <= 30 && ran < 40){
num2 += 1; tol2 += ran;
}
if(ran <= 40 && ran < 50){
num3 += 1; tol3 += ran;
}
col[i]= ran;
}
for(int i = 0; i < 49; i++ ){
if(i == 7 || i == 14 || i == 21 || i == 28 || i == 35 ||i == 42){
System.out.println("\n");
}
System.out.printf(("%7d"),+ col[i]);
}
System.out.printf("\n");
System.out.printf("Found "+ num1 +" number(s) in the 20s "+ "totaling "+ tol1);
System.out.printf("\nFound "+ num2 +" number(s) in the 30s "+ "totaling "+ tol2);
System.out.printf("\nFound "+ num3 +" number(s) in the 40s "+ "totaling "+ tol3);
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)