Skip to content

Latest commit

 

History

History
30 lines (19 loc) · 793 Bytes

File metadata and controls

30 lines (19 loc) · 793 Bytes

Core elements of programs - Operations

Introduction

Computers can do math. But how can you get them to do Math for you?

It's not really that hard at all. When executing a line, if it's got Maths or something in it, it will simply evaluate it according to BODMAS.

It'll probably be clearer with an example:

System.out.println(2*(5+(3/2));

Will give 13.

You can also do this with variables -

int bestestNumber = 8;
int worstestNumber = 3;
System.out.println((bestestNumber%worstestNumber)*3);

Remember from Variables that % is the modulus operator - it is just the remainder. e.g. 9%4=1 as 9/4 gives a remainder of 1

The computer would see this as (8%3)*3 = (2)*3 = 6.

There's not really much else to say. Bit of a short lesson really. ¯_(ツ)_/¯.