In: Computer Science
I need the program to continue asking the user for a positive value and NOT skip to the value for store 2 if a negative value is entered. This is the code so far: Thanks
public static void main(String[] args) {
Scanner input = new
Scanner(System.in);//scanner
int Store [] = new int[5];//array
for five int
for(int i=0;i<5;i++) { // loops
until five inputs are entered
System.out.println("Enter today's sale for store "+ (i+1) +" (negative value not allowed)");
Store [i] = input.nextInt();//allows user
input
}// end of for
System.out.println("SALES BAR CHART");
for(int i =0; i<5 ;i++) { // for loop to print out store number
System.out.println("Store "+ (i+1) +": ");
for(int j=0; j < Store [i];j =j+100) { // for loop to print number of asterisks
System.out.print("*");
}// end of
for loop for asterisks
System.out.println();
}// end of for loop
}//end of
main
}//end of class
import java.util.Scanner; public class SalesChart { public static void main(String[] args) { Scanner input = new Scanner(System.in);//scanner int Store[] = new int[5];//array for five int for (int i = 0; i < 5; i++) { // loops until five inputs are entered do { System.out.println("Enter today's sale for store " + (i + 1) + " (negative value not allowed)"); Store[i] = input.nextInt();//allows user input } while (Store[i] < 0); }// end of for System.out.println("SALES BAR CHART"); for (int i = 0; i < 5; i++) { // for loop to print out store number System.out.println("Store " + (i + 1) + ": "); for (int j = 0; j < Store[i]; j = j + 100) { // for loop to print number of asterisks System.out.print("*"); }// end of for loop for asterisks System.out.println(); }// end of for loop }//end of main }//end of class