The code can be optimized by replacing the "if" statement with a modulo operation. This can be done by changing the line “if(i%2==0){” to “if(i%2){”. This will check if the value of “i” is divisible by 2, which should be done more efficiently than the if statement.
for(int i=0;i<=n;i++){
    if(i%2==0){
        System.out.println(i);
    }
}
Suggerire modi per ottimizzare il codice nel blocco dato.