A-simple-Calculator | A simple calculator using HTML , CSS & Javascript | Apps library
kandi X-RAY | A-simple-Calculator Summary
kandi X-RAY | A-simple-Calculator Summary
A simple calculator using HTML, CSS & Javascript This is a simple calculator functionality achieved using Javascript. The logic is very simple with the minimum lines of code possible.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of A-simple-Calculator
A-simple-Calculator Key Features
A-simple-Calculator Examples and Code Snippets
Community Discussions
Trending Discussions on A-simple-Calculator
QUESTION
I'm using a tutorial online but it seems that it might be a bit outdated? Here it is if you guys want it: https://www.instructables.com/id/How-to-Make-a-Simple-Calculator-in-Java/
...ANSWER
Answered 2020-Jan-30 at 00:09import java.util.Scanner;
public class MathOperations {
public static void main(String[] args){
int firstNumber = 0;
int secondNumber = 0;
char operator;
double answer = 0.0;
Scanner scanObject = new Scanner(System.in);
System.out.println("Please enter your first number: ");
firstNumber = scanObject.nextInt();
System.out.println("Please enter your second number");
secondNumber = scanObject.nextInt();
System.out.println("Addition, substraction, multiplcation, or dividing? ");
operator = scanObject.next().charAt(0);
switch (operator){
case 'A': answer = firstNumber + secondNumber;
}
}
}
QUESTION
I tried to create a calculator using multiple boolean types on one "if" command. I also tried to use the numbers 42(*),43(+),45(-) and 47(/) from the ASCII table instead of the symbols. Now, for some resson it's not working both with the numbers and the symbols and I would like to know why. I know how to solve the problem using different methods but i want to understand the logic of why my programm isn't working, thanks for anyone who can help!
One of the different methods: [Trouble with a simple calculator code (Java)
...ANSWER
Answered 2017-Dec-24 at 20:39The original problem is with the line System.out.println(num5+action+num6+"=");
where you attempt to form a String from 2 doubles and a character. This will perform numeric calculation before casting to a String. To concatenate to form a String, you can simply use System.out.println(num5 + "" + action + "" + num6 + "" + "=");
You also asked if there is a better way to solve the equation without a tone of if-statements - Not very elegantly unfortunately. You can use a switch statement to make it somewhat more legible, such as below. There is a JavaScript ScriptEngine library for Java you may be interested in, but if you know what the inputs will be the Switch statement is as good as you will get.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install A-simple-Calculator
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page