File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help

 
tayy abdelqader
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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));
 
Mishra Anshu
Ranch Hand
Posts: 224
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please mind the quotes here PrintAny("temp");.

So, the "temp" there is no loger an int , but a string.
Just remove the quotes.
 
tayy abdelqader
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem in the method

i can not deal with it

i have tried what u told me useless
 
sushma sree
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx sushma sree
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic