# Thread: Calculate average age for women and men?

1. Member
Join Date
Apr 2007
Location
Sweden
Posts
12
Rep Power
0

## Calculate average age for women and men?

Hi!
I have just started with Java and found this forum before I have been doing a lot of reading here but now I need some help since I´m stuck.
I want to make a program that will calculate the averageage for women and and men one group for women and one for men.At the end the program should say buy buy and then show the averageage for women and men.
The program looks like this.
import javax.swing.*;

public class Person {

public static void main(String [] arg) {

String kvinna;

String man;

String txt= "";

int start= JOptionPane.showConfirmDialog(null,"Välkommen!"+

"\nVill du räkna medelåldern?", "Fråga", JOptionPane.YES_NO_OPTION);

if (start == 0){

for (int i=1 ; i>= 0; i++) {

for(int j=1 ;j <= i; j++){

int knapp= JOptionPane.showConfirmDialog(null,"En kvinna?");

if(knapp == 0) {

kvinna= JOptionPane.showInputDialog("Hur gammal är kvinnan?");

if (false)

break;

else {

int k1= Integer.parseInt(kvinna);

int medel1= k1 / j;

String txt1= txt + medel1;
}
}

else if(knapp == 1) {

man= JOptionPane.showInputDialog("Hur gammal är mannen?");

if (false)

break;

else {

int m1= Integer.parseInt(man);

int medel2= m1 / j;

String txt2= txt +medel2;

}
}

else

break;

} // for1 slut

} // for2 slsut

} // if1 slut

else

System.exit(0);

//JOptionPane.showMessageDialog(null,"Medelåldern för kvinnor är: " + txt1 + "\nMedelåldern för män är: " + txt2);( this is the calculation for women and men)

//System.exit(0);
} //main slut
} //class slut

Thansk for input and help in advance.

2. Senior Member
Join Date
Mar 2007
Posts
134
Rep Power
0
For me it was difficult to understand spanish , Look at the code let me know the status

Java Code:
```package com.test.workarea;

import javax.swing.JOptionPane;

public class Person {

public static void main(String [] arg) {

String kvinna;

String man;

String txt= "";
int i=0,j=0;
int sumk1=0,summ1 =0;

int start= JOptionPane.showConfirmDialog(null,"V&#228;lkommen!"+

"\nVill du r&#228;kna medel&#229;ldern?", "Fr&#229;ga", JOptionPane.YES_NO_OPTION);

while(start == 0){

int knapp= JOptionPane.showConfirmDialog(null,"En kvinna?");

if(knapp == 0) {

kvinna= JOptionPane.showInputDialog("Hur gammal &#228;r kvinnan?");// Assumes this asks men

if(kvinna != null ){

int k1= Integer.parseInt(kvinna);
sumk1 = sumk1 + k1;
i = i +1;
}
}

else if(knapp == 1) {

man= JOptionPane.showInputDialog("Hur gammal &#228;r mannen?"); //Assumes this asks women
if(man != null){
int m1= Integer.parseInt(man);
summ1 = summ1 + m1;
j = j +1;
}

}

else

break;

} // if1 slut

JOptionPane.showMessageDialog(null,"Medel&#229;ldern f&#246;r kvinnor &#228;r: " + sumk1/i + "\nMedel&#229;ldern f&#246;r m&#228;n &#228;r: " + summ1/j);//( this is the calculation for women and men)
System.exit(0);

//		System.exit(0);
} //main slut
} //class slut```

3. Member
Join Date
Apr 2007
Location
Sweden
Posts
12
Rep Power
0

## Thank you goldhouse!

Thanks for your help it works fine now I can continue on my own now.
Thanks again from Legoland

4. Senior Member
Join Date
Mar 2007
Posts
134
Rep Power
0
you are welcome... dont hesitate to ask more :)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•