0% found this document useful (0 votes)
30 views4 pages

Oop 1

This document contains a student's assignment on Java programming concepts. It includes sample code with errors and the corrected code showing proper syntax and formatting for if/else statements, while loops, and variable declarations. The assignment provides examples of common programming mistakes and their correct implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Oop 1

This document contains a student's assignment on Java programming concepts. It includes sample code with errors and the corrected code showing proper syntax and formatting for if/else statements, while loops, and variable declarations. The assignment provides examples of common programming mistakes and their correct implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NAMA : CHRISTOPHER EVAN HARJONO

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 )
{

System.out.println ( "Age greater than or equal to 65" ) ;


}
else
{
System.out.println ( "Age is less than 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

You might also like