Watch more such videos in below playlist: Java Tutorial: ruclips.net/p/PLhyraTKIsw5_WemVMvshNm-0aC7zfISCO Java Programs: ruclips.net/p/PLhyraTKIsw59nQJKvZTKmNK2aMxHwvLOa
Write a program for calculators in java which performs addition, subtraction, multiplication and division of any two numbers. Take user input using Scanner class and print the results of every calculation. do it
We can return the value of result since it is declared under main function.. we just needed to print result so it was printed within main, but you can return it as well if using another function for switch case
you can ask the user to provide input as one of these 4 operators as a string, and based on the operator and other 2 numbers, the calculations can be done
35/45 gives us result as 0.77 usually but in the Java code we are taking both these numbers as integers and that's why the result of division operation is also integer in this case - 0.77 is taken as 0 in the result.. Change the data type to double for both the inputs taken and you'll get the result as 0.77 Hope this helps 👍
Watch more such videos in below playlist:
Java Tutorial: ruclips.net/p/PLhyraTKIsw5_WemVMvshNm-0aC7zfISCO
Java Programs: ruclips.net/p/PLhyraTKIsw59nQJKvZTKmNK2aMxHwvLOa
This helped me understand switches more thx bro
welcome. share with your friends!
Wahh.... Brilliant job... Nice explanation.. Keep it up 💯👏
Thanks a lot 😊
Write a program for calculators in java which performs addition, subtraction, multiplication and division of any two numbers. Take user input using Scanner class and print the results of every calculation.
do it
Your explanation is very good keep going : )
Thank you, I will
Thanks for the video it helped me a lot ❤️
Glad it helped!
How we can do the arithmetic operation???
Eg - 1+2-5(3*4)
so much thank full to you sir...
Most welcome
Is this the only method using switch case
I mean what if we just don't want the user to give the operator or value and declare it by ourselves?????
You can make the calculator using other algorithms as well.. there are multiple ways
Dont we need to return the value of result or is it restricted in switch statement?
We can return the value of result since it is declared under main function.. we just needed to print result so it was printed within main, but you can return it as well if using another function for switch case
@@programmingforbeginners7392 thank you
Bro you made a mistake which was in 4th operator. You have to put n2=0 System.out.println ("invalid");
Or other things words like that
Thank you so much 🙏
You're welcome 😊
Thanks bro
Welcome
thank you
You're welcome
the code is showing that the operator is defined first and then again why the declaration is again required
Is it necessary to write result =0 , can't we just start from switch
no
Can you tell me how to use multiple operators
😅
where is the modulus operator??
How to make operator as + - × /
you can ask the user to provide input as one of these 4 operators as a string, and based on the operator and other 2 numbers, the calculations can be done
thank you so much. it helps me a lot..
Welcome. Subscribe and share with your friends 😀
you should consider that you cannot divide by 0
It’ll give a logical error
how can the program should keep on executing automatically after onetime completion plz let me know
Put it in while(true) loop to run continuously
bro how to give continuous input without running programe again and again
Put the code inside loop to continuously use the calculator
@@programmingforbeginners7392
Bro when I given exit option on the time wise program was get exit other wise prog still running wht a loop i use
If I choose division and entered two nos as 35 and 45 then it gives me result as 0
Please explain
35/45 gives us result as 0.77 usually but in the Java code we are taking both these numbers as integers and that's why the result of division operation is also integer in this case - 0.77 is taken as 0 in the result..
Change the data type to double for both the inputs taken and you'll get the result as 0.77
Hope this helps 👍
@@programmingforbeginners7392 i have tried but still it is not working properly and it did not print the correct value.
can you please provide your code?
Double and float data types can be used in switch statements
@@programmingforbeginners7392not working
wow
Thanks 👍