You are on page 1of 7

UNIVERSITAS GUNADARMA

Pemrograman
Berorientasi Objek
Java Programing , tugas-2 (Struktur Kontrol)
Herawati
NPM : 10108959
Kelas : 3KA14
Run JAVA dengan JAVA EDITOR NETBEANS
Dengan menggunakan struktur kontrol : FOR , IF ..ELSE, dan break dan Array
Coding Program:

package javaapplication3;
/**
* @author hera
*/
public class Main {
public static void main(String[] args) {
// TODO code application logic here
String names[]={"Retno","yolan","Karin","Dian","Ayu","Hera","Meli","Imah","Aisyah"};
String searchName = "Ayu";
boolean foundName = false;
for( int i=0; i< names.length; i++ ){
if( names[i].equals( searchName )){
foundName = true;
break;} }
if( foundName ) System.out.println( searchName + " ditemukan!" );
else System.out.println( searchName + " tidak ditemukan." );
}
}

Dengan menggunakan struktur kontrol : switch case


Coding Program :
package javaapplication5;
/**
* @author hera
*/
public class Main {
public static void main( String[] args )
{
int grade = 50;
switch(grade){
case 100:
System.out.println( "Excellent!" );
break;
case 90:
System.out.println("Bagus!" );
break;
case 80:
System.out.println("Belajar lagi!" );
break;
default:
System.out.println("Maaf, Anda gagal.");
}
}

Do…While
While ..