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.
Code Java:
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
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.
Code java:
int summa(int tal1, int tal2);
I will comment on this line as it is a common mistake.
Code java:
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).
Re: Help with assignments Methods Java
You need to learn C++ before you can even do any of this
Re: Help with assignments Methods Java
Quote:
Originally Posted by
Java Sucks
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.
Re: Help with assignments Methods Java
Quote:
Originally Posted by
Junky
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
Re: Help with assignments Methods Java
Quote:
Originally Posted by
Java Sucks
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