Simple Java Guide - Part 2

Discussion in 'Archives' started by Jokerz, May 29, 2008.

Simple Java Guide - Part 2
  1. Unread #1 - May 29, 2008 at 11:33 PM
  2. Jokerz
    Joined:
    Apr 24, 2008
    Posts:
    610
    Referrals:
    0
    Sythe Gold:
    0

    Jokerz Forum Addict

    Simple Java Guide - Part 2

    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!
     
  3. Unread #2 - Jun 10, 2008 at 10:43 PM
  4. Scrubs
    Joined:
    Mar 4, 2008
    Posts:
    68
    Referrals:
    0
    Sythe Gold:
    0

    Scrubs Member

    Simple Java Guide - Part 2

    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!
     
  5. Unread #3 - Jun 14, 2008 at 2:40 PM
  6. Uber l33t
    Joined:
    Jun 14, 2008
    Posts:
    208
    Referrals:
    0
    Sythe Gold:
    0

    Uber l33t Active Member
    Banned

    Simple Java Guide - Part 2

    Good job on making it easy. You get an A+ ;)
     
  7. Unread #4 - Jun 29, 2008 at 7:35 PM
  8. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,211
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Simple Java Guide - Part 2

    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 :/
     
  9. Unread #5 - Aug 30, 2008 at 3:20 PM
  10. joking
    Joined:
    Nov 9, 2007
    Posts:
    736
    Referrals:
    3
    Sythe Gold:
    0

    joking Apprentice
    Do Not Trade

    Simple Java Guide - Part 2

    looks good and straight forward. i enjoyed reading this thx alot
     
  11. Unread #6 - Nov 3, 2008 at 4:13 PM
  12. Noob!
    Joined:
    Aug 29, 2008
    Posts:
    322
    Referrals:
    0
    Sythe Gold:
    0

    Noob! Forum Addict
    Banned

    Simple Java Guide - Part 2

    strait forward guide! 9/10
     
  13. Unread #7 - Dec 30, 2008 at 9:59 PM
  14. ruanwennan
    Referrals:
    0

    ruanwennan Guest

    Simple Java Guide - Part 2

  15. Unread #8 - Jan 1, 2009 at 10:59 PM
  16. broady
    Joined:
    Nov 15, 2008
    Posts:
    22
    Referrals:
    0
    Sythe Gold:
    0

    broady Newcomer

    Simple Java Guide - Part 2

    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;
     
< Can i come back? | Selling lvl 3 66 fish! 300k+ in bank! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site