Assalamu'alaikum?..
selamat malam semua, sudah pada tidur kah anda?.. duh saya mah belum nih, baru selesai mengerjakan tugas, lumayan juga, agak pusing. kali ini akan saya coba bagikan pada sahabat semua, semoga bermanfaat.
berikut programnya, kopas, sliahkan menikmati:
selamat malam semua, sudah pada tidur kah anda?.. duh saya mah belum nih, baru selesai mengerjakan tugas, lumayan juga, agak pusing. kali ini akan saya coba bagikan pada sahabat semua, semoga bermanfaat.
berikut programnya, kopas, sliahkan menikmati:
LABELED BREAK STATEMENT
public class Labeled_Break_Statement{
public static void main (String[] args){
int [][] numbers={{1,2,3},{4,5,6},{7,8,9}};
int searchNum=5;
boolean foundNum=false;
searchLabel:
for(int i=0; i<numbers.length; i++){
for(int j=0; j<numbers[i].length; j++){
if(searchNum==numbers[i][j]){
foundNum=true;
break searchLabel;
}
}
}
if(foundNum){
System.out.println(searchNum+ " Ada Lho !");
}
else{
System.out.println(searchNum+ "Tidak Ada Euy !");
}
}}
public static void main (String[] args){
int [][] numbers={{1,2,3},{4,5,6},{7,8,9}};
int searchNum=5;
boolean foundNum=false;
searchLabel:
for(int i=0; i<numbers.length; i++){
for(int j=0; j<numbers[i].length; j++){
if(searchNum==numbers[i][j]){
foundNum=true;
break searchLabel;
}
}
}
if(foundNum){
System.out.println(searchNum+ " Ada Lho !");
}
else{
System.out.println(searchNum+ "Tidak Ada Euy !");
}
}}
LABELED CONTINUE STATEMENT
public class Labeled_Continue_Statement{//public = modifier, class = class, labeleddst = nama kelas
public static void main (String [] args){
outerLoop:
for (int i=0; i<5; i++){
for (int j=0; j<0; j++){
System.out.println ("Inside forj) loop"); //Message 1
if (j == 2) continue outerLoop;
}
System.out.println ("Inside for(i) loop"); //Message 2
}
}
}
public static void main (String [] args){
outerLoop:
for (int i=0; i<5; i++){
for (int j=0; j<0; j++){
System.out.println ("Inside forj) loop"); //Message 1
if (j == 2) continue outerLoop;
}
System.out.println ("Inside for(i) loop"); //Message 2
}
}
}
Tampilan Program:
UNLABELED BREAK STATEMENT
class Unlabeled_Break_Statement{
public static void main (String [] args){
String names[]={"Beah", "Bianca", "Lance", "Belle", "Nico", "Yza"};
String searchName="Yza";
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 !!!");
}
}
}
public static void main (String [] args){
String names[]={"Beah", "Bianca", "Lance", "Belle", "Nico", "Yza"};
String searchName="Yza";
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 !!!");
}
}
}
Tampilan Program
UNLABELED CONTINUE STATEMENT
public class Unlabeled_Continue_Statement{
public static void main (String[] args){
String names[]={"Beah", "Bianca", "Lance", "Beah"};
int count=0;
for(int i=0; i<names.length; i++){
if(!names[i].equals("Beah")){
continue;
}
count++;
}
System.out.println("There Are "+count +"Beah in The List");
}
}
public static void main (String[] args){
String names[]={"Beah", "Bianca", "Lance", "Beah"};
int count=0;
for(int i=0; i<names.length; i++){
if(!names[i].equals("Beah")){
continue;
}
count++;
}
System.out.println("There Are "+count +"Beah in The List");
}
}
Tampilan Program
Demikian lah yang bisa saya bagikan sekarang, silahkan dimodifikasi dan dikembangkan, semoga bermanfaat:..
Wassalam.
Sumber Referensi : Tugas Mata Kuliah Pemrograman Berorientasi Objek
Wassalam.
Sumber Referensi : Tugas Mata Kuliah Pemrograman Berorientasi Objek