Can exceptions be created to a selective control structure (If-Else)?

0

My problem is in a prime number algorithm. The logic that I used in Java was the following:

public static void main(String[] args) {

    Scanner entrada = new Scanner (System.in);


    System.out.print("Su rango de numeros primos es del 1 hasta: ");
    int ultimoNumero = entrada.nextInt();
    System.out.println("----------------------------------------------\n\n");

    System.out.println("INICIO\n\n");

    int vNumero;
    System.out.println("2\n3\n5\n7");
    for (vNumero = 2; vNumero<=ultimoNumero; vNumero++){

        if (vNumero%1==0 & vNumero%2!=0 & vNumero%3!=0 & vNumero%4!=0 & vNumero%5!=0 & vNumero%6!=0 & vNumero%7!=0 
            & vNumero%8!=0 & vNumero%9!=0 & vNumero%vNumero==0){

            System.out.println(vNumero);

        }     
}

    System.out.println("FIN");

I know it's not a good way to do this algorithm, since I would not print the 2,3,5 and 7. That's why the question came to my mind. Can exceptions be made to the initial condition?

    
asked by DarkSlayer 15.06.2017 в 01:54
source

0 answers