Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fefong/java_calculator

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Simple Calculator

Example Application: calculator

Sum

x + y

Example

System.out.println(String.format("%.2f + %.2f = %.2f", x, y, x + y));

Subtraction

x - y

Example

System.out.println(String.format("%.2f - %.2f = %.2f", x, y, x - y));

Multiplication

x * y

Example

System.out.println(String.format("%.2f * %.2f = %.2f", x, y, x * y));

Division

x / y

Example

System.out.println(String.format("%.2f / %.2f = %.2f", x, y, x / y));

GET PI

Import:

import java.lang.Math;

Code:

Math.PI

Example

System.out.println("PI: " + Math.PI);

Exponent

Import:

import java.lang.Math;

Code:

Math.pow(x, y)

Example

	System.out.println(String.format("%.2f ^ %.2f = %.2f", x, y, Math.pow(x, y)));

Random

Import:

import java.lang.Math;

Generate random integers in a range.

new Random().nextInt(x) 

Example

Random integer in a range between min: 0 (inclusive) and max: X (inclusive).

System.out.println("Random Number: "+ new Random().nextInt(10));

Square Root of x

Import:

import java.lang.Math;

Code:

Math.sqrt(x)

Example

System.out.println(String.format("Square Root of %.2f = %.2f", x, Math.sqrt(x)));

Some links for more in depth learning

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.