Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: my code didnt perform its function

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default my code didnt perform its function

    i wrote a simple code which compiled but failed to actually work
    this is wat it looks like

    // This is a simple code that code that adds x + y = z using the values x =4, y = 2
     
    class Arithmetic {
     
       int x;
       short y;
       int z;
     
          /*Do the computations*/   
     
     
       public static void main(String args[]) {
         int x = 4;
        int y = 2;
        int z = x + y;//compute z
     
            /* use integer values in place of x and y*/
             System.out.println("z = x + y");
             System.out.println("The value of z");
    }
    }

    pls i need help my first write up on my own and its given me concerns
    Last edited by copeg; September 20th, 2010 at 05:48 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: my code didnt perform its function

    Please define what you mean by works...this could be quite a few things. My first guess is that you want it to print z?
    System.out.println(z);

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: my code didnt perform its function

    wat i meant by it didnt work is dat it was supposed to add the values the of x and y and print it as a new value for z

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: my code didnt perform its function

    Please do not start a second thread that asks the exact same question you just posted in this thread...I have removed your other post.

    Next, see my post above. Printing things between quotes treats the value as a string...if you wish to print the actual value, send System.out.println() the actual value
    System.out.println("z");//print the string 'z'
    System.out.println(z);//prints the value of z

  5. The Following User Says Thank You to copeg For This Useful Post:

    jamal (September 21st, 2010)

  6. #5
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: my code didnt perform its function

    wat i meant by it didnt work is dat
    Recommended reading:
    How To Ask Questions The Smart Way

    db

  7. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    jamal (September 21st, 2010)

  8. #6
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: my code didnt perform its function

    thanks for d info i have actually solved d problem

Similar Threads

  1. Need Help on the Interface Function
    By yel_hiei in forum Object Oriented Programming
    Replies: 12
    Last Post: July 29th, 2010, 07:27 AM
  2. Substring function
    By bristol580 in forum Java SE APIs
    Replies: 2
    Last Post: November 12th, 2009, 11:29 AM
  3. How to Pass unlimited Arguments to a Function
    By neo_2010 in forum Java Programming Tutorials
    Replies: 2
    Last Post: July 8th, 2009, 11:39 AM
  4. Function of difference between two numbers
    By uplink600 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 13th, 2009, 05:57 AM
  5. Traverse Function for Knights tour
    By budder8818 in forum Java Theory & Questions
    Replies: 0
    Last Post: February 4th, 2009, 03:49 PM