View: 2632|Reply: 4
|
nak tny soalan, pasal switch case
[Copy link]
|
|
ok..aku ade buat 1 program ni..pakai switch case...
org kena buat pilihan dari 1 hingga 7 then akan kua output...tapi, aku nak buat, kalau user enter 0, program tu akan end, camne nak buat ek??tlg ajar... |
|
|
|
|
|
|
|
- class Tutorial
- {
- public static void main (String argv[])
- {
- int value=Integer.parseInt(argv[0]);
-
- switch(value)
- {
- case 0:
- System.out.print( "End Program" );
- break;
-
- case 1:
- System.out.print( "welcome" ) ;
- break;
-
- case 2:
- System.out.print( "orang_letrik hensem" );
- break;
-
- default:
- System.out.print( "ape kes!" );
- break;
- }
- }
- }
Copy the Code
case ni ko boleh up sampai bape yang ko suke...
kalo ko nak ada 7 case, ko tambah je la...
setiap statement dalam case adalah penting...
sama ada ko nak process data ke...nak display ke. etc... |
|
|
|
|
|
|
|
System.exit(0);
or
System.exit(1);
tak ingat which one..sila google
case 0:
System.out.print( "End Program" );
System.exit(1); |
|
|
|
|
|
|
|
Reply #1 Kezman's post
program pakai language aper...
kalau vb case 0 : END; |
|
|
|
|
|
|
|
Reply #3 adekmanes's post
System.exit(0)....coding ni utk tamatkan sistem dalam java language.. |
|
|
|
|
|
|
| |
|