Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- class project2{
- public static void main(String[] param) {
- users();
- System.exit(0);
- }
- public static void users() {
- String[] names = new String[5];
- String[] ages = new String[5];
- String a;
- String b = null;
- for (int i = 1; i < names.length; i++) {
- a = JOptionPane.showInputDialog(null, "What's your name, user " + i + "?");
- b = JOptionPane.showInputDialog(null, "What is your age, " + a + "?");
- names[i] = a;
- ages[i] = b;
- }
- int agecount=0;
- for (int i = 1; i < names.length; i++) {
- agecount+=Integer.parseInt(ages[i]);
- System.out.println("User " + i + ": " + names[i] + " " + ages[i] + " years old");
- }
- double avarageAge=agecount/(double)names.length;
- System.out.println("The avarage age for this quiz is " + avarageAge);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment