Variables, Methods and Parameters Comments
Comments
-
love the quotes btw
-
i really need guide to learn this. How could i be better in this kind off stuff??? very difficult. help me
-
@Fatin, we will be launching a programming bootcamp this week to provide more help with learning a topic.
-
This one was a doozy for me. I tried to change the variable name(doStuff) and create new values within the name variable I created. Anyways I must have written 3 or 4 lines, just to find out I only needed to simple lines :( .
-
I love this site. Thank you very much!
-
Excellent.
-
Brilliant way to teach! I have been searching through out the whole web for a sophisticated JAVA learn by doing site! Really glad to say that I have fortunate enough to experience learneroo.com! :)
-
I don't solve the problem...
Would someone help me?import java.util.Scanner;
public class Main {
public static int doStuff(int a, int b){
a =10;
b =20;int sum=a+b;
return(sum)/2;a= 14;
b = -14;int sum=a+b;
return(sum)/2;} //your code here
}
//boilerplate code public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); for(int i=0; i<n; i++){ int a = in.nextInt(); int b= in.nextInt(); int result = doStuff(a, b); System.out.println(result); } }
}
-
Awesome!
-
Wow Simple
-
Excellent site, I have tried codebat, codeacdemy, udemy, tutorialpoint, learnjavaonline.org, http://docs.oracle.com/javase/tutorial/ but this is the best so far
int mySum = a + b; //creates variable to hold sum of a = b
return mySum/2; //return average -
The quotes are definitely motivating :)
-
You can also do it in one line instead of setting a+b to a variable you can just return it all return (a + b)/2
-
It is taking a very long time to show the results and it is really annoying.
-
I was more confused about the value of int a and int b then anything i couldn't work out how it had come to the results if no number have been declared. so i was trying to declare it the whole time which failed me.
-
i think this code will be efficient if we generalize both the numerator and denominator with a variable(s) and give a condition where denominator is >0
-
Its not as complicated as it first seems. Just remember how the order of operations works when you write the code.
-
Hi @Yuta, the code is simple
int sum = a + b;
return sum / 2;you are putting variable sum inside parenthesis which is wrong.
-
ahh specifying parameters is what got me as well Mezbaur
-
-
the simplest answer is to put return a/2+b/2 for you idiots who can't figure it out for yourselves
-
Have tried several times but getting "Compilation failed" Where do I go to check the correct coding?
-
lol..seriously? made several lines and giving values to int a and b. This is fun
-
can i use public static void main (string []args) instead of public static int doStuff
-
If you look at the code on the bottom you'll see that main method there, which calls the method doStuff. (See static and main methods for more info.)
-
just put return a/2+b/2 where it says your code here
yuta -
oh That was so easy.
-
public static int doStuff(int a, int b){ int sum = a + b; return (sum)/2; }
-
It takes more time to run the code
-
return (a+b)/2;
Is a better answer then storing it on a variable first -
this site is very useful to me to learn javacoding..
-
There is no value of A & B then how it's working. tell me any one
-
what is use of public and static
-
this one is hard for me
actually have no idea what to do -
i had to cheat
-
Janardhan
Sep 13, 6:27 AMnice website... but i would like to know how the code is being executed in browser