- Create a new project and class with the names of Arirthmetic
- Paste the code below into your code view
- Hit the run button and see what appears in the console
- Now try changing it up in a bit and see what you can do.
Arithmetic Code
[java]
public class Arithmetic
{
public static void main ( String [ ] args )
{
System.out.println(5 / 3 * 2) ;
System.out.println(7 / 3 + 2) ;
System.out.println(7 / 3 + "rem" ) ;
System.out.println(7 % 3) ;
}
}
[/java]
Explaination
This code snippet also makes use of the print line function. This time instead of posting a string of characters like in Hello World, it performs calculations.
If we wanted it to display the actual numbers, we would enclose them in quotation marks like in the 3rd example / line.
Every calculation in this snippet is pritty basic, but if you didnt know the % is basically just getting the remainder of the the calculation. So for this example it would be 1, because 3 goes into 7 twice with 1 remainder.
Thats it! More tutorials coming soon