Why can I not execute the following code? When I try to run it, I get a message that there is no main method.
import java.util.*;
import java.text.*;
public class NumberFormatter
{
public static void main(String args[])
{
double amount = 1276789.34;
double percent = 0.95;
Locale india = new Locale("en", "IN");
Locale america = new Locale("en", "US");
Locale germany = new Locale("de", "DE");
NumberFormat nfIndia = NumberFormat.getNumberInstance(india);
NumberFormat nfAmerica = NumberFormat.getNumberInstance(america);
NumberFormat nfGermany = NumberFormat.getNumberInstance(germany);
System.out.println(nfIndia.format(amount));
System.out.println(nfAmerica.format(amount));
System.out.println(nfGermany.format(amount));
nfIndia = NumberFormat.getCurrencyInstance(india);
nfAmerica = NumberFormat.getCurrencyInstance(america);
nfGermany = NumberFormat.getCurrencyInstance(germany);
System.out.println(nfIndia.format(amount));
System.out.println(nfAmerica.format(amount));
System.out.println(nfGermany.format(amount));
nfIndia = NumberFormat.getPercentInstance(india);
nfAmerica = NumberFormat.getPercentInstance(america);
nfGermany = NumberFormat.getPercentInstance(germany);
System.out.print(nfIndia.format(percent));
System.out.println(nfAmerica.format(percent));
System.out.println(nfGermany.format(percent));
}
}
Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.
Can you post the exact error message? Also please read the forum FAQ about use of code tags.
Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.
Class "NumberFormatter" does not have a main method.
Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.
Quote:
Originally Posted by
TheCoder
Class "NumberFormatter" does not have a main method.
Again, please look up use of [code] [/code] tags when posting code.
Your code itself looks OK to me, so the problem is elsewhere. Are you sure that you're trying to run the correct class file, one that is from compiling the above code?
Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.
I will double check, thanks
Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.
It works for me. Probably left out a } in the original code.