in this Occasion will of course try to make with the control program uses the switch-case, and this time some earnest Also attempting to bring java programming language. how the syntax is before us to implementasika in programming languages:
syntax in the program control switches case are as follows:
switch () {
this case-value:
Code to execute if == this-value
break;
That case-value:
Code to execute if That-value ==
break;
...
default:
Code to execute if does not equal the value Following any of the cases
break;
}
and below is the implementation of a conversion program using the switch on the case, why menggnaka switch case because memunyai a limited extent.
import java.util.Scanner;
public class MyClass {
public static void main() {
int hari_ke;
String hari;
Scanner input = new Scanner(System.in);
System.out.print(“masukan hari_ke;”);
System.out.print(“\n”);
hari_ke = input.nextInt();
switch (hari_ke)
{
case 1 :
hari = “senin”;
break;
case 2 :
hari = “selasa”;
break;
case 3 :
hari = “rabu”;
break;
case 4 :
hari = “kamis”;
break;
case 5 :
hari = “jumat”;
break;
case 6 :
hari = “sabtu”;
break;
default:
hari = “minggu”;
break;
}
System.out.print(“hari_ke”);
System.out.print(hari_ke);
System.out.print(“adalah”);
System.out.print(hari);
System.out.print(“\n”);
return 0;
}
}
0 comments:
Posting Komentar