Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

help with creating methods in Java?

In java, I created a program like this

public class test1{

public static int damagedealt(int dd){

dd = 6;

return dd;

public static void main(String [] args){

int dd = 5

System.out.println(damagedealt(dd));

it outputs 6, but I did it before so that it outputs 11.

How did I make it output 11, because I want to do it again. Help Please!

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    well you see.... the damagedealt method just sets dd to 6 and returns it.

    So it doesn't matter what number you put in for that method, you're going to get 6.

    Change it to:

    public static int damageDealt(int dd){

    return dd;

    }

  • 8 years ago

    I think you added the dd in the function, which is 6, to the argument you gave to the function which is 5

    Your function might be like

    public static int damagedealt(int dd) {

    dd += 6;

    return dd;

    }

    this seems to be the most logical option

Still have questions? Get your answers by asking now.