-2
A program that provides information on job applicants: The number of candidates per sex.... There is an error in this if, ta returning only m
or just f
package livroex_pag69;
import javax.swing.JOptionPane;
public class Ex_09_Recrutamento {
public static void main(String[] args){
String sexo, exp, esc, continuar ;
int idade, m = 0, f = 0, numCand = 1;
do{
idade = Integer.parseInt(JOptionPane.showInputDialog("Idade: "));
sexo = JOptionPane.showInputDialog("Sexo [m/f]: ");
esc = JOptionPane.showInputDialog("Cite a escolaridade: ");
exp = JOptionPane.showInputDialog("Possui experiência [s/n]: ");
numCand++;
continuar = JOptionPane.showInputDialog("Deseja continuar? [s/n] ");
}while(continuar.equals("s"));
for (int i = 1; i < numCand; i++){
if(sexo.equals("m")){
m++;
}else{
f++;
}
}
JOptionPane.showMessageDialog(null, "Número de candidatos masculino: " + m+
"\n Número de candidatos feminino: "+f);
}
}
Your logic is incorrect, because the "for" will only be executed when it continues to be different from s, so there will only be one result, always return only one sex, reevaluate your while loop
– Eduardo Gonçalves
Hello Thiago, welcome to Sopt, before starting a look at our [Tour] -- I made a change in the title and description of your question if my change does not represent your need you can reverse it by accessing this link and choosing the review that best suits you. = D
– Icaro Martins
Obg Icaro, as there is the character limit, I get lost in this part. Valew.
– Thiago