Advertisement
cynthiarez

Potential answer to adding up total loop inputs

Sep 17th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // Class list (String adding-on upon doing while loop.
  2. // Outputs all of the Strings being saved during the while loop.
  3.  
  4.  
  5. int counter = 1, total;
  6. String name, names="";
  7.  
  8. total = Integer.parseInt(JOptionPane.showInputDialog("Enter total number of students"));
  9.  
  10. while (counter<=total)
  11. {
  12. name = JOptionPane.showInputDialog("Enter student's name");
  13. names += name + "\n";
  14. counter++;
  15.  
  16. }
  17.  
  18. JOptionPane.showMessageDialog(null,"Class is full");
  19. JOptionPane.showMessageDialog(null,"Class list below: " + "\n" + names);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement