Forums Register Login

help

+Pie Number of slices to send: Send
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);


}

}
+Pie Number of slices to send: Send
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));
+Pie Number of slices to send: Send
Please mind the quotes here PrintAny("temp");.

So, the "temp" there is no loger an int , but a string.
Just remove the quotes.
+Pie Number of slices to send: Send
the problem in the method

i can not deal with it

i have tried what u told me useless
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
thanx sushma sree
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 914 times.
Similar Threads
display error
static methods can't be overidden why
Passing value from one method to the next
testing for integer
can we redefine a final variable of the interface in a class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:03:46.