problem in understanding output.
public class Function2
{
public static void main(String[] args)
{
sumAll(10,20,30);
sumAll('a',10,10);
}
public static void sumAll(int a, int b, int c)
{
int sum = a+b+c;
System.out.println(sum);
}
public static void sumAll(String a, int b, int c)
{
}
}
Output –
60
117
Why 117, it should be a20. If it is correct, then when will it display a20.
Re: problem in understanding output.
In the second method, 'a' is a char, not a String. I am assuming that the compiler is getting it's ASCII value and then using the first sumAll() method.
Re: problem in understanding output.
If I put "a" instead of 'a', will it display a20.
Re: problem in understanding output.
No it wouldn't since the second method doesn't do anything at all. There wouldn't be any result from it.
Re: problem in understanding output.
I want to display output a20.
What should be the code then?
Re: problem in understanding output.
Create an empty String variable in the sumAll() method then concatenate a and the sum of b and c
Re: problem in understanding output.
string sum = a+b+c;
where a is string and b,c are integers.
Will it work then?
Re: problem in understanding output.
That would print out this: a1010
Wrap b + c in parenthesis to force it to add them together then add it to the String.
Re: problem in understanding output.