calculator

Calculator application including keyboard input in java swing

走远了吗. 提交于 2019-11-28 02:03:46
I have a calculator application in java swing, which is working properly with mouse click input. Now I want it to read input using keyboard button stroke. I had heard about the glass pane in java tutorial, but i need to know any other simple method to meet the requirement. KeyPadPanel is an example that uses Action and Key Bindings for numeric entry. 来源: https://stackoverflow.com/questions/10099686/calculator-application-including-keyboard-input-in-java-swing

How does a simple calculator with parentheses work?

雨燕双飞 提交于 2019-11-27 19:24:46
I want to learn how calculators work. For example, say we have inputs in infix notation like this: 1 + 2 x 10 - 2 The parser would have to respect common rules in math. In the above example this means: 1 + (2 x 10) - 2 = 19 (rather than 3 x 10 - 2 = 28) And then consider this: 1 + 2 x ((2 / 9) + 7) - 2 Does it involve an Abstract Syntax Tree? A binary tree? How is the order of operations ensured to be mathematically correct? Must I use the shunting-yard algorithm to convert this to postfix notation? And then, how would I parse it in postfix notation? Why convert in the first place? Is there a

how to calculate distance while walking in android?

戏子无情 提交于 2019-11-27 17:53:29
I am developing a demo for my app, in which there are two buttons named as "START" and "STOP". When user taps on "START" he will start walking. What I want to do is make it so that when users tap "STOP" then the demo will calculate his distance between "START" and "STOP". If the user pressed "START" and pressed "STOP" without taking a single step, then it must show 0km or 0m. I don't have any idea how I should start this; please make a suggestion. One way to go about it is using the accelerometer data. Your app should continuously record the accelerometer data after the user presses the Start

String calculator [closed]

我们两清 提交于 2019-11-27 15:19:40
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Hi fellow programmers, I am creating a calculator in C# and I have a string variable math which contains 100 * 5 - 2 How can I display its output which is 498 in my console? My code is this: String math = "100 * 5 - 2"; Console.WriteLine(math); Console.ReadLine(); // For Pause So

Decimal to Fraction conversion in Swift

杀马特。学长 韩版系。学妹 提交于 2019-11-27 14:30:29
I am building a calculator and want it to automatically convert every decimal into a fraction. So if the user calculates an expression for which the answer is "0.333333...", it would return "1/3". For "0.25" it would return "1/4". Using GCD, as found here ( Decimal to fraction conversion ), I have figured out how to convert any rational, terminating decimal into a decimal, but this does not work on any decimal that repeats (like .333333). Every other function for this on stack overflow is in Objective-C. But I need a function in my swift app! So a translated version of this ( https:/

How can I solve equations in Python? [closed]

柔情痞子 提交于 2019-11-27 11:57:04
Let's say I have an equation: 2x + 6 = 12 With algebra we can see that x = 3 . How can I make a program in Python that can solve for x ? I'm new to programming, and I looked at eval() and exec() but I can't figure out how to make them do what I want. I do not want to use external libraries (e.g. SAGE), I want to do this in just plain Python. How about SymPy ? Their solver looks like what you need. Have a look at their source code if you want to build the library yourself… There are two ways to approach this problem: numerically and symbolically. To solve it numerically, you have to first

Is there a calculator with LaTeX-syntax?

混江龙づ霸主 提交于 2019-11-27 09:45:14
问题 When I write math in LaTeX I often need to perform simple arithmetic on numbers in my LaTeX source, like 515.1544 + 454 = ??? . I usually copy-paste the LaTeX code into Google to get the result, but I still have to manually change the syntax, e.g. \frac{154,7}{25} - (289 - \frac{1337}{42}) must be changed to 154,7/25 - (289 - 1337/42) It seems trivial to write a program to do this for the most commonly used operations. Is there a calculator which understand this syntax? EDIT: I know that

Java Doubles are not good at math [closed]

末鹿安然 提交于 2019-11-27 07:39:58
问题 I am currently writing a calculator program in java. It is my first java program, I am used to c++. I have noticed that doubles in java are not at all like doubles in c++. try this in java and c++ 4.1*3 that/.1 it should be 12.3 then 123, and c++ gives this result but java gives 12.299999999999999 and 122.99999999999999 How can I do math like in c++ with doubles, I understand that anything you would use 12.299999999999999 in a program at all would make no difference compared to 12.3, but when

How do I change the number of decimal places iOS?

流过昼夜 提交于 2019-11-27 06:22:55
问题 I have a simple calculator app and I want it to be so that if the answer requires no decimal places, there are none, just whole numbers. If the answer was 2, I don't want it to say 2.000000, it should say 2. If it requires one decimal place, it should show to one decimal place for example 12.8 instead of 12.80. How would I do this? Here is my code. btw, this is from a tutorial at http://www.youtube.com/watch?v=Ihw0cfNOrr4, not my own work. viewcontroller.h #import <UIKit/UIKit.h> interface

Accurate calculation of CPU usage given in percentage in Linux?

拜拜、爱过 提交于 2019-11-26 23:56:34
问题 It's a question which has been asked many times, however there is no well supported answer I could find. Many people suggest the use of top command, but if you run top once (because you have a script for example collecting Cpu usage every 1 second) it will always give the same Cpu usage result (example 1, example 2). A more accurate way to calculate CPU usage, is by reading the values from /proc/stat , but most of the answers use only the first 4 fields from /proc/stat to calculate it (one