Skip to main content

help me pls?

1 reply [Last post]
dyinghero
Offline
Joined: 2007-06-28
Points: 0

I have here the code, it's a method call...
What the code does is that, the main function calls asks for a number from the user, then the method(function) heading displays the output and never returns the value from the man function... if you got confused on my details, here's my code, maybe you guys can figure this out...thanks ^^

import javax.swing.JOptionPane;

public class method4
{
public static void main (String args[])
{
int n1 = Integer.parseInt(JOptionPane.showInputDialog("Enter 1st number: "));
int n2 = Integer.parseInt(JOptionPane.showInputDialog("Enter 2nd number: "));
int prod = n1 * n2;
}

public static void prod(n1 , n2)
{

JOptionPane.showMessageDialog(null, "The Product is: " +prod(n1 , n2));
System.exit(0);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
briand
Offline
Joined: 2005-07-11
Points: 0

I think you are probably addressing this to the wrong forum. This is
a performance forum and this is not a performance question.

Regardless, you never call prod(), so you'll never out put the result.
In fact, this code will not even compile, as there are no type specifications
for the n1 and n2 arguments to prod. Furthermore, you have a recursive
call to prod(), which you probably didn't intend.

Brian