• Log in or sign up for an account here: https://www.sythe.org/login

Simple Java Guide - Part 2

Jokerz

Forum Addict
Joined
Apr 24, 2008
Sythe Gold
0
Messages
610
Location
Australia
Welcome to another guide by me :)

I will be demonstrating how to compute to numbers to get the product of the numbers.

Shall we start?

From my other guide you will have learn't to define a class.

Start with this:

Code:
class Compute {

Just like before we shall add

Code:
public static void main(String args[])

Now to call the numbers we will need to use the Integer method, Remember Integers will be the main statement you will use.


Add this:

Code:
int num;

This will declare that a variable will be used as a int and it will be called num

Time to assign a number to it:

Code:
num = 200;

Now lets print that bit out

Code:
System.out.println("This is num: " + num;

Now time to assign a second set to Multiply num

Code:
num = num * 2;

Ok now time to print the whole thing out!

Code:
System.out.print("The value of num * 2 is ");
Code:
System.out.println(num);

}

}

If you read my previous guide you will have learnt how to compile a program. So compile this and now open it up.

Your output display should show:

This is num: 100
The value of num * 2 is 200

num will be 100 so you will have multiplied 100 * 2 :)

Hope you enjoyed this guide!
 
Very good, simple guide. Good thing you didn't try to sound like a smartass and just end up making it complicated for some. Good job!
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
System.out.println("This is num: " + num);


you need the )... :/

you could do


int num = 200;

System.out.print("The value of num * 2 is " + num + "!");


thats better :/
 
looks good and straight forward. i enjoyed reading this thx alot
 
Wrong.

You re-assigned the value of "num", so the value of "num" is actually now 400. num*2 would be 800.

Also, a few tips.

int num;
num = 200;

can be simplified to:

int num = 200;

num = num * 2; can be simplified to

num *= 2;
 
Runescape Gamblingrunescape gambling
Back
Top