0
Not intialized...?? Variable z.
public class Program { public static void main(String[] args) { double p=1; double S=0; int x=6; int n=5; int m=2; double z; if(2*x>m){ for(int i=1;i<=n;i++) p=p*(2*i+1); z=x/2+3*p; } else if(2*x<=m){ for(int k=1;k<=n;k++) if(k!=3 && k!=4) S=S+(k+x); z=x/3-2*S; } System.out.println("Prodhimi:"+p); System.out.println("Shuma:"+S); System.out.println("Rezultati:"+z); } }
3 Antworten
+ 1
double z = 0;
In your code, all statements that give value to z, are located in a nested block, which may or may not run. Therefore the compiler can't be sure if z is initialized, and you cannot print it if not initialized.
At the time of declaration, give it a starting value. If you are sure that the nested blocks will run whatever happens, then the initial value doesn't matter anyway.