Data Types Comments
Comments
-
@William the only class that can be public is Main. So either remove 'public' or rename the class to 'Main'.
-
First getting an error while compiling about return statement missing, wheb added about incompatible types - required String, found double
Here the code:public static String doStuff(int a, double b){
double sum = a+b;
return sum;
String message = "The sum is "+ sum;
}Hint and cheat missing, what's wrong in my code? Thx
-
@Honzis, you need to return a String that contains the correct message. So remove
return sum
and returnmessage
instead. -
Thanks for the quick answer, got it now. :)
-
public static String doStuff(int a, double b){
String valor;
double soma = a + b;
return valor = "The sum is" + soma;
}it worked!!
so pay attention to the position to the indentation -
@isnard, indentation doesn't matter in Java. you can see the featured submission for the standard answer.
-
I got a quote by Albert Einstein:
"A clever person solves a problem. A wise person avoids it."
So... should I avoid the challenge? :P
-
whats the answer to the return output?
-
What is the code to solve this
-
@pat, I added an explanation, which you can 'cheat' to view.
-
Don't system.out.print, return.
-
WHY CAN I NOT DO THIS
-
@William, in this question You should implement code in doStuff() method and return the message. my code
-
@Honzis , You should return only a string type in doStuff() method. because return type of doStuff method is string, check my code :) my code
-
Or you could cast a double on the sum my code
-
Just FYI, I had originally put my string as "The sum is: " + sum. It said it was incorrect because I put the : in. So, even though it ran fine, gave the correct answer, etc., it showed incorrect
due to that. Just for any others who may have missed it for something that tiny and couldn't figure out why what they were doing was wrong.
-
import java.util.Scanner;
public class DataTypes
{
public static void main(String[] args)
{
int a;
double b;
Scanner input = new Scanner(System.in);System.out.println ("Enter an integer number: "); a = input.nextInt(); System.out.println ("Enter an double number: "); b = input.nextDouble(); double sum = a+b; String result = "Your sum is " + sum; System.out.println (result); }
}
-
The exercise is to get you to understand how to attach a variable into a string, over complicating the output or process only clouds the issue. keep it simple like this...
String answer = "The sum is " + (a+b);
return answer;
William Kennedy
Oct 12, 8:35 AMIt doesn't seem to compile my answer but it runs on Eclipse just fine.
Here is my code
public class DataTypes {
}