madhawaseeeee

madhawa

Nov 3rd, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. class project2{
  4.  
  5. public static void main(String[] param) {
  6.  
  7. users();
  8. System.exit(0);
  9.  
  10. }
  11.  
  12. public static void users() {
  13.  
  14. String[] names = new String[5];
  15. String[] ages = new String[5];
  16. String a;
  17. String b = null;
  18.  
  19. for (int i = 1; i < names.length; i++) {
  20.  
  21. a = JOptionPane.showInputDialog(null, "What's your name, user " + i + "?");
  22. b = JOptionPane.showInputDialog(null, "What is your age, " + a + "?");
  23.  
  24. names[i] = a;
  25. ages[i] = b;
  26.  
  27. }
  28.  
  29. int agecount=0;
  30.  
  31. for (int i = 1; i < names.length; i++) {
  32. agecount+=Integer.parseInt(ages[i]);
  33. System.out.println("User " + i + ": " + names[i] + " " + ages[i] + " years old");
  34. }
  35. double avarageAge=agecount/(double)names.length;
  36.  
  37. System.out.println("The avarage age for this quiz is " + avarageAge);
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment