Oop 1
Oop 1
NIM : 18.K1.0078
TUGAS
19 MARET 2020
1. a.Error:
• dibagian if ada titik koma
• variable age tidak terdefinisi tipe datanya(int,float,char)
• kurang tanda {} dibagian if ( age >= 65) {}else{}
Correct:
if ( age >= 65 )
{
b.Error:
Correct:
int x = 1, total = 0 ;
while ( x <= 10 )
{
total += x ;
++x ;
}
c.Error:
Correct:
int x = 1 ;
while ( x <= 100 )
{
total += x ;
++x ;
}
d.Error:
• variable y tidak terdefinisi jenis tipe datanya(int,float,char)
Correct:
y=1;
while ( y > 0 )
{
System.out.println( y ) ;
++y ;
}
2. a.
b.
3. public class Tugas
{
public static void main( String args[] )
{
int a = 1 , b = 0 , c =0 ;
while (a <= 10)
{
b= a * a ;
c += b ;
System.out.println(a+ " * " +a+ " = " +b) ;
++a ;
}//end of while
System.out.println("Total is " +c ) ;
} // endmain
} // end class Tugas