aspose file tools*
The moose likes Beginning Java and the fly likes help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help" Watch "help" New topic
Author

help

tayy abdelqader
Greenhorn

Joined: Dec 11, 2005
Posts: 20
I have this code I do not knwo the exact problem

I whant to get a nomber but it gives me the (temp)

what shal i do

here is the code

import javax.swing.*;

public class Aha
{

public static void main(String[]args)
{
int temp=Integer.parseInt(JOptionPane.showInputDialog("Enter any value here"));

int val=10;
PrintAny("temp");

temp+=val;

}

static void PrintAny(String temp)
{
System.out.println(temp);
System.exit(0);


}

}
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Your PrintAny method takes a String -- not an int. One way to handle this is to convert your int to a String before passing it to the method.

int val = 10;
PrintAny(Integer.toString(val));


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Mishra Anshu
Ranch Hand

Joined: Sep 16, 2003
Posts: 224
Please mind the quotes here PrintAny("temp");.

So, the "temp" there is no loger an int , but a string.
Just remove the quotes.


"Ignorance is bliss"
tayy abdelqader
Greenhorn

Joined: Dec 11, 2005
Posts: 20
the problem in the method

i can not deal with it

i have tried what u told me useless
sushma sree
Greenhorn

Joined: Mar 27, 2006
Posts: 12
public class Aha
{

public static void main(String[]args)
{
int temp=Integer.parseInt
(JOptionPane.showInputDialog("Enter any value here"));

int val=10;
temp+=val;
PrintAny(temp);

}

static void PrintAny(int temp)
{
System.out.println(temp);
System.exit(0);
}

}

Look at the code above which is a modification of your version. I am sure you want to add 10 to the value entered by user, print it out and then exit. So, first of all, if you call printAny() before temp+=val, then the temp value would never be updated since you are exiting out of the program. And also saying printAny("temp") would pass the String "temp" but not the int value in temp. So change it to printAny(temp) and at the same time, modify your printAny(String temp) to printAny(int temp) since you are passing an integer. The above code should run fine without any errors
tayy abdelqader
Greenhorn

Joined: Dec 11, 2005
Posts: 20
thanx sushma sree
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help
 
Similar Threads
can we redefine a final variable of the interface in a class
display error
static methods can't be overidden why
Passing value from one method to the next
testing for integer