Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

variabel diskon migh not have been initialized

Fri Oct 28, 2011 5:43 pm

Code:
public static void main(String[] argsthrows IOException{
        
        
int nofaktur ;
        
int kodebrang ;
        
double jmltransaksi;
        
double hargabarang;
        
double totalharga;
        
double diskon ;
        
double totalbayar;
DataInputStream input = new DataInputStream(System.in);
System.out.print("input nofaktur ="); nofaktur=Integer.parseInt(input.readLine());
System.out.print("input kodebarang ="); kodebrang=Integer.parseInt(input.readLine());
System.out.print("jmltransaksi = "); jmltransaksi=Integer.parseInt(input.readLine());

if (
kodebrang == 1
{
    
hargabarang 500000;
}
else if (
kodebrang==2
{
    
hargabarang 100000;
}
else 
{
hargabarang 50000;
}

totalharga hargabarang jmltransaksi;{
    
if ((
kodebrang == 1)&&(jmltransaksi >= 10))
diskon =  (int) (100 totalharga);}
else if (((
kodebrang== 1)||(kodebrang== 2)&&(jmltransaksi >= 5)))
diskon =  (int) (100 totalharga);}

 
totalbayar=totalharga-diskon ;
    
System.out.print("hargabarang =");System.out.print(hargabarang);
System.out.print("totalharga =");System.out.print(totalharga);
System.out.print("diskon =");System.out.print(diskon);
System.out.print("totalbayar =");System.out.print(totalbayar);
    }
    }




help me please



Re: variabel diskon migh not have been initialized

Mon Nov 07, 2011 12:32 am

you have to give initial values for within function defined variables which are :
Code:

      int nofaktur 
=0;
        
int kodebrang=;
        
double jmltransaksi=0.0d;
        
double hargabarang=0.0d;
        
double totalharga=0.0d;
        
double diskon=0.0d ;
        
double totalbayar=0.0d;
 


Post a reply