CLASS 4: Calculator Using Switch Statement In Java - MeraForum Community.No 1 Pakistani Forum Community

MeraForum Community.No 1 Pakistani Forum Community

link| link| link
MeraForum Community.No 1 Pakistani Forum Community » The World of Information » Computer and Information Technology » Java » CLASS 4: Calculator Using Switch Statement In Java
Java All about Java Programs

Advertisement
 
Post New Thread  Reply
 
Thread Tools Display Modes
(#1)
Old
Morash's Avatar
Morash Morash is offline
 


Posts: 17,781
My Photos: ()
Country:
Star Sign:
Join Date: Jul 2010
Location: ▌║█║▌│█│║▌║
Gender: Male
cool CLASS 4: Calculator Using Switch Statement In Java - >>   Show Printable Version  Show Printable Version   Email this Page  Email this Page   04-17-2014, 01:01 AM



Calculator In Java Using Switch Statement




The switch Statement Is Used As A Reciprocal Of nested if else Statements. It Is Used When Multiple Choices Are Given And One Choice Is To Be Selected.
The 'nested if-else' Structure Becomes Complicated In Multiple Choices So Then We Used switch Statement.
One Of The Choices Or Cases In The switch Statement Is Executed Depending Upon The Value Returned By The Expression.

In The switch Statement The break Statement Is Normally Used At The End Of Statements In Each Case. It Exits The Control From The Body Of switch Structure.
If It Is Not Used Then The Statements Of Other Cases That Come After The Matching Case Will Also Be Executed.


Syntax

switch(expression)
{
case constant:
statement;
break;
}




Example Of Making A Calculator







Output


Addition





Subtraction




Multiplication




Division




 





bE driveN wiTh puRpOse, Be r313n71355 in your alιgnмenт;
with excellence.
pAy n0 mInd to the ∂ιsιмραssισηε∂ เ๓ק๏tєภt ђคtєгร

.. нoolιgan
Reply With Quote Share on facebook
Sponsored Links
(#2)
Old
pakeeza's Avatar
pakeeza pakeeza is offline
 


Posts: 28,336
My Photos: ()
Country:
Star Sign:
Join Date: Jan 2012
Location: Maa ki duaon mey
Gender: Female
Default Re: CLASS 4: Calculator Using Switch Statement In Java - >>   Show Printable Version  Show Printable Version   Email this Page  Email this Page   04-17-2014, 10:19 AM

Gooo shaarIng

 



Be Positive... Everything Gonna be Alright

(#3)
Old
AYAZ's Avatar
AYAZ AYAZ is offline
 


Posts: 12,370
My Photos: ()
Country:
Star Sign:
Join Date: Aug 2008
Location: Karachi
Gender: Male
Default Re: CLASS 4: Calculator Using Switch Statement In Java - >>   Show Printable Version  Show Printable Version   Email this Page  Email this Page   04-19-2014, 07:09 PM

This is great share morash, I will try this and will let you know if I have any question about it

 







ALLAH FARMATA HAI :
AEY BANDEY JO HUA
WO ACHA HUA .
JO HORAHA HAI ACHA HO RAHA HAI.
JO HOGA WO BHI ACHA HOGA.
TERA KIYA GAIYA JO TU ROTA HAI
TU KIA LAYA JO TU NE KHO DIYA.
JO LIYA YAHIN (DUNYA) SEI LIYA
JO DIYA YAHIN (DUNYA) PE DIYA
JO AAJ TERA HAI PEHLAY KISI AUR KA THA
AUR KAL KISI AUR KA HOGA.
TABDEELI KAINAAT KA MAMOOL HAI
BAS TU WO JAMA KAR JO TU SATH LEI KAR JANEY WALA HAI
YANI NAIK AMAAL.


(#4)
Old
Akash Akash is offline
The Bold And Beautiful
 


Posts: 1,111
My Photos: ()
Country:
Star Sign:
Join Date: Feb 2014
Location: Peshawar
Gender: Male
Default Re: CLASS 4: Calculator Using Switch Statement In Java - >>   Show Printable Version  Show Printable Version   Email this Page  Email this Page   04-19-2014, 11:12 PM

nice sharing bro da java ba za sta na yadom khu ma di rab tek no. zama tol fan chi sok di salamona warla waya

 






(#5)
Old
AYAZ's Avatar
AYAZ AYAZ is offline
 


Posts: 12,370
My Photos: ()
Country:
Star Sign:
Join Date: Aug 2008
Location: Karachi
Gender: Male
Default Re: CLASS 4: Calculator Using Switch Statement In Java - >>   Show Printable Version  Show Printable Version   Email this Page  Email this Page   04-20-2014, 08:32 PM

Morash check this code, It's giving me error don't know why

Code:
package cal;
import java.util.Scanner;

/**
 *
 * @author Ayaz
 */
public class cal
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        float num1 , num2;
String operations;

Scanner input = new Scanner (System.in);
System.out.print("Enter the First number");
num1 = input.nextFloat();

System.out.print("Enter the operation");
operations = input.next();

System.out.print("Enter the Second Number");
num2= input.nextFloat();

switch (operations){
    
    
    case "+":
    System.out.print("Addition of "+num1+"and "+num2+" is =  "+ (num1 + num2));
    break;

    case "-":
    System.out.print("Substraction of "+num1+"and "+num2+" is = "+ (num1 - num2));
    break;
    
    case "/":
    System.out.print ("Division of "+num1+" and "+num2+" is" = + (num1 / num2));
    break;

    case "*":
    System.out.print("Multiplication  of "+num1+" and "+num2+" is" = + (num1 * num2));
    break;


    

   }
    }}

 







ALLAH FARMATA HAI :
AEY BANDEY JO HUA
WO ACHA HUA .
JO HORAHA HAI ACHA HO RAHA HAI.
JO HOGA WO BHI ACHA HOGA.
TERA KIYA GAIYA JO TU ROTA HAI
TU KIA LAYA JO TU NE KHO DIYA.
JO LIYA YAHIN (DUNYA) SEI LIYA
JO DIYA YAHIN (DUNYA) PE DIYA
JO AAJ TERA HAI PEHLAY KISI AUR KA THA
AUR KAL KISI AUR KA HOGA.
TABDEELI KAINAAT KA MAMOOL HAI
BAS TU WO JAMA KAR JO TU SATH LEI KAR JANEY WALA HAI
YANI NAIK AMAAL.


(#6)
Old
Morash's Avatar
Morash Morash is offline
 


Posts: 17,781
My Photos: ()
Country:
Star Sign:
Join Date: Jul 2010
Location: ▌║█║▌│█│║▌║
Gender: Male
Default Re: CLASS 4: Calculator Using Switch Statement In Java - >>   Show Printable Version  Show Printable Version   Email this Page  Email this Page   04-22-2014, 11:05 PM

Quote:
Originally Posted by AYAZ View Post
Morash check this code, It's giving me error don't know why

Code:
package cal;
import java.util.Scanner;

/**
 *
 * @author Ayaz
 */
public class cal
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        float num1 , num2;
String operations;

Scanner input = new Scanner (System.in);
System.out.print("Enter the First number");
num1 = input.nextFloat();

System.out.print("Enter the operation");
operations = input.next();

System.out.print("Enter the Second Number");
num2= input.nextFloat();

switch (operations){
    
    
    case "+":
    System.out.print("Addition of "+num1+"and "+num2+" is =  "+ (num1 + num2));
    break;

    case "-":
    System.out.print("Substraction of "+num1+"and "+num2+" is = "+ (num1 - num2));
    break;
    
    case "/":
    System.out.print ("Division of "+num1+" and "+num2+" is" = + (num1 / num2));
    break;

    case "*":
    System.out.print("Multiplication  of "+num1+" and "+num2+" is" = + (num1 * num2));
    break;


    

   }
    }}
Your Package And Cal Class Names Are Same, Change cal Class Name To Cal (Capital C)
Last 2 Jo System.out.print K Statements Hai Os Mai is K Saath Jo Double Commas Lage Hai, Wo Remove Karo And Equal Sign K Baad Lagana ..

 





bE driveN wiTh puRpOse, Be r313n71355 in your alιgnмenт;
with excellence.
pAy n0 mInd to the ∂ιsιмραssισηε∂ เ๓ק๏tєภt ђคtєгร

.. нoolιgan
(#7)
Old
AYAZ's Avatar
AYAZ AYAZ is offline
 


Posts: 12,370
My Photos: ()
Country:
Star Sign:
Join Date: Aug 2008
Location: Karachi
Gender: Male
Default Re: CLASS 4: Calculator Using Switch Statement In Java - >>   Show Printable Version  Show Printable Version   Email this Page  Email this Page   04-23-2014, 02:23 AM

Thanks morash.

 







ALLAH FARMATA HAI :
AEY BANDEY JO HUA
WO ACHA HUA .
JO HORAHA HAI ACHA HO RAHA HAI.
JO HOGA WO BHI ACHA HOGA.
TERA KIYA GAIYA JO TU ROTA HAI
TU KIA LAYA JO TU NE KHO DIYA.
JO LIYA YAHIN (DUNYA) SEI LIYA
JO DIYA YAHIN (DUNYA) PE DIYA
JO AAJ TERA HAI PEHLAY KISI AUR KA THA
AUR KAL KISI AUR KA HOGA.
TABDEELI KAINAAT KA MAMOOL HAI
BAS TU WO JAMA KAR JO TU SATH LEI KAR JANEY WALA HAI
YANI NAIK AMAAL.


Post New Thread  Reply

Bookmarks

Tags
calculator, class, java, statement, switch

« Previous Thread | Next Thread »
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
3rd Class: if Statement In C++ Morash C++ 11 05-05-2015 02:18 AM
CLASS 3: if else Statement In Java Morash Java 6 04-12-2014 01:13 AM
CLASS 2: How To Take Input In Java Morash Java 4 04-10-2014 01:13 AM
CLASS 1: How To Run And Print Message On Screen Using Java Through NetBeans IDE Morash Java 12 04-09-2014 02:49 PM
Please silent or switch off your cell phone ღƬαsнι☣Rασ™ General Discussion 17 04-18-2011 12:13 PM


All times are GMT +5. The time now is 03:32 PM.
Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.

All the logos and copyrights are the property of their respective owners. All stuff found on this site is posted by members / users and displayed here as they are believed to be in the "public domain". If you are the rightful owner of any content posted here, and object to them being displayed, please contact us and it will be removed promptly.

Nav Item BG