Skip to content

Navigation Menu

Sign in
Sign up

Latest commit

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date

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

About

Example Application: calculator

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /