简体   繁体   中英

It doesnt ask for input, goes straight thru

Its a simple java code, and when i compile it,no errors show up, cumpiling just fine. But when i run it, goes straight thru, doesnt ask for any input or show any output... Cant tell wy its happening, im a begginer so if somebody can tell me how to get it running...

import java.util.Scanner;
public class Empresa{
    public static void main(String[] args) {
        int cod, nasc, ingr, atual=2018, i=0;
        Scanner entrada = new Scanner(System.in);
        while(i>3){
            i++;
        System.out.println("Escreva o codigo do funcionario:");
        cod = entrada.nextInt();
        System.out.println("Escreva o ano de nascimento do funcionario:");
        nasc = entrada.nextInt();
        System.out.println("Escreva o ano de ingresso do funcionario:");
        ingr = entrada.nextInt();
        if(((atual-nasc)>=65)||((atual-ingr)>=30)||(((atual-nasc)>=60)&&((atual-ingr)>=25)))
            System.out.println("Requerer aposentadoria");
        else
            System.out.println("Nao requerer");
    }
}

}

    import java.util.Scanner;
    public class Empresa{
    public static void main(String[] args) {
        int cod=0, nasc=0, ingr=0, atual=2018, i=0;
        Scanner entrada = new Scanner(System.in);
        while(i<3){
            i++;
        System.out.println("Escreva o codigo do funcionario:");
        cod = entrada.nextInt();
        System.out.println("Escreva o ano de nascimento do funcionario:");
        nasc = entrada.nextInt();
        System.out.println("Escreva o ano de ingresso do funcionario:");
        ingr = entrada.nextInt();
        if(((atual-nasc)>=65)||((atual-ingr)>=30)||(((atual-nasc)>=60)&&((atual-ingr)>=25)))
            System.out.println("Requerer aposentadoria");
        else
            System.out.println("Nao requerer");
    }
}

You need to set value for integers and fix your while, if your code wont run again, you should share your error..

Wrong logic in while loop. As i=0 and your loop condition is i>3 , which will return false and loop block wouldn't be executed. Change the loop condition to i<3 which will return true until i is shorter than 3 and loop block will be executed 3 times.

import java.util.Scanner;
    public class Empresa{
    public static void main(String[] args) {
        int cod=0, nasc=0, ingr=0, atual=2018, i=0;
        Scanner entrada = new Scanner(System.in);
        while(i<3){
            i++;
        System.out.println("Escreva o codigo do funcionario:");
        cod = entrada.nextInt();
        System.out.println("Escreva o ano de nascimento do funcionario:");
        nasc = entrada.nextInt();
        System.out.println("Escreva o ano de ingresso do funcionario:");
        ingr = entrada.nextInt();
        if(((atual-nasc)>=65)||((atual-ingr)>=30)||(((atual-nasc)>=60)&&((atual-ingr)>=25)))
            System.out.println("Requerer aposentadoria");
        else
            System.out.println("Nao requerer");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM