CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2632|Reply: 4

nak tny soalan, pasal switch case

[Copy link]
Post time 3-2-2008 03:23 AM | Show all posts |Read mode
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...
Reply

Use magic Report


ADVERTISEMENT


Post time 3-2-2008 07:46 AM | Show all posts

  1. class Tutorial
  2. {
  3.         public static void main (String argv[])
  4.         {
  5.                 int value=Integer.parseInt(argv[0]);
  6.                
  7.                 switch(value)
  8.                 {
  9.                         case 0:
  10.                                 System.out.print( "End Program" );
  11.                                 break;
  12.                        
  13.                         case 1:
  14.                                 System.out.print( "welcome" ) ;
  15.                                 break;
  16.                        
  17.                         case 2:
  18.                                 System.out.print( "orang_letrik hensem" );
  19.                                 break;
  20.                                
  21.                         default:
  22.                                 System.out.print( "ape kes!" );
  23.                                 break;
  24.                 }
  25.         }
  26. }
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...
Reply

Use magic Report

Post time 6-2-2008 11:51 AM | Show all posts
System.exit(0);
or
System.exit(1);

tak ingat which one..sila google


case 0:
                                System.out.print( "End Program" );
                                System.exit(1);
Reply

Use magic Report

Post time 7-2-2008 12:33 AM | Show all posts

Reply #1 Kezman's post

program pakai language aper...


kalau vb case 0 : END;
Reply

Use magic Report

Post time 13-2-2008 10:05 AM | Show all posts

Reply #3 adekmanes's post

System.exit(0)....coding ni utk tamatkan sistem dalam java language..
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

7-1-2025 06:04 AM GMT+8 , Processed in 0.188687 second(s), 18 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list