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: Help with assignments Methods Java

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with assignments Methods Java

    Hi

    I'm currently learing Java with my book and a teacher at long distance.

    I send him my two recent assignments about methods and he told me that they was not correct and gave me some tips and one was to search online so here I em hoping someoen could help me.

    The first assignment was to make a method that add together two numbers that the user types in.

    here is my code for that one. it is in swedish so some varibels and text might seem strange.

    Public class ovning_1{
    Public static void main(String[] args){
    System.out.print(“mata in det första talet: ”);
    int tal1 = Keyboard.readint();
    System.out.print(”mata in det andra talet: ”);
    int tal2 = Keyboard.readint();
     
     int summa(int tal1, int tal2);
     
     System.out.println(” summan av ” + tal1 + tal2 + ”är ” + summa); 
     
    }
    static int summa(int tal1, int tal2) {
    int summa = (tal1+tal2);
    Return summa 
    }
    }
     
     
     
    The second one is to make a method that reads a number that the user types in and return true if it's 0 or bigger and false if smaller than 0.
     
    here is my code for that one.
     
     
    Public class ovning_2{
    Public static void main(String[] args){
    System.out.print(“Skriv in boooloendet: ”);
    int tal1 = Keyboard.readint();
     
    system.out.println(”ditt boolon är” + boolean);
     
     
    }
     
    Static Boolean(int tal1){
    Int boolean;
    If (tal >=0){
    boolean = ture
    }
     
    esle
     
    boo = false
    Retun boo2;
    }
    }


    I would appreciate any help on these and since it's some in swedish sry for my bad english and try to be simple if your going yo explain complicated things since I'm still learning.

    thanks in advance


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,469
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: Help with assignments Methods Java

    Did you try and compile your code? There are so many errors you should compile and read the error messages. As soon as you get the error messages don't just post them here and whine "my code doesn't compile". Try to actually understand what the error message says. If you do you will improve your understanding and allow you to debug your own code in the future.
    int summa(int tal1, int tal2);
    I will comment on this line as it is a common mistake.
    int x = 5;
    int y = 10;
    int z = int x + int y;
    Hopefully you understand what is wrong with that last line of code above. Well you have done the same thing in your code. Plus there is also another error on that same line(yours not mine).

  3. #3
    Banned
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with assignments Methods Java

    You need to learn C++ before you can even do any of this

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,469
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: Help with assignments Methods Java

    Quote Originally Posted by Java Sucks View Post
    You need to learn C++ before you can even do any of this
    That is totally incorrect. Many people manage to learn Java without seeing any C or C++ code.

  5. #5
    Banned
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with assignments Methods Java

    Quote Originally Posted by Junky View Post
    That is totally incorrect. Many people manage to learn Java without seeing any C or C++ code.
    oh sorry. I just thought that everything would be easier if you do C++ first

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Help with assignments Methods Java

    Quote Originally Posted by Java Sucks View Post
    oh sorry. I just thought that everything would be easier if you do C++ first
    What made you think that? With a username such as yours, together with some of the more recent answers you have provided, I'd recommend providing more informative answers to be taken even remotely seriously (as opposed to a troll)

    To the original poster, it helps to boil your problem down to an SSCCE, which helps both you and use understand the problem at hand
    Last edited by copeg; June 8th, 2011 at 08:40 PM.

Similar Threads

  1. Looking for practice problems/assignments
    By tkgraham in forum Member Introductions
    Replies: 2
    Last Post: April 4th, 2011, 10:28 PM
  2. Using Protected Methods, in a Java Library
    By WACman in forum Object Oriented Programming
    Replies: 2
    Last Post: March 10th, 2011, 04:42 PM
  3. 2 Java methods and a sorting algorithm
    By Tiberius in forum Algorithms & Recursion
    Replies: 0
    Last Post: February 26th, 2011, 02:41 PM
  4. A couple of basic java assignments, need help!
    By barnabus in forum Paid Java Projects
    Replies: 1
    Last Post: August 18th, 2010, 10:18 AM
  5. Novice with java methods, please help!
    By raidcomputer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 14th, 2009, 04:23 AM