Data Types Comments


  • It doesn't seem to compile my answer but it runs on Eclipse just fine.
    Here is my code

    public class DataTypes {

    public static void main(String[] args) {
            int a = 2;
            double b = 7.5;
            double sum = a + b;
            System.out.println("The sum is" +  sum);


  • @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:

  • @Honzis, you need to return a String that contains the correct message. So remove return sum and return message 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.


  • @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

  • import java.util.Scanner;
    public class DataTypes
    public static void main(String[] args)
    int a;
    double b;
    Scanner input = new Scanner(;

  • 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;

Contact Us
Sign in or email us at [email protected]