1) Like Stultuske stated, your main method is empty
public static void main (String []args){
}
2) Why would you use the * operator on a string?
String []name= {
"Zero"*10,"One"*10,"Two"*10, ...
3) Why would you set the first String in your array to your welcoming message?
int i=0;
name[i]=JOptionPane.showMessageDialog(null,"Welcome to Java Program!!")
4) Why save the number he entered in the int "i" but never use it again?
String st1=JOptionPane.showInputDialog("Insert a Number between 0-9999");{
i=Integer.parseInt(st1);
System.out.println ("0-9999");
5) Why save the "continue?" answer in st2 then test if st1 is equal to "yes" ?
String st2=JOptionPane.showInputDialog ("Do you want another try?");
if (st1.equals ("yes"))
{
}
6) There is no looping mechanism in your algorithm
7) There is no algorithm to decide which string to print according to the number saved in st1
Asking you to modify this code would be longer than re-writing it , the whole structure is wrong, heres a what it should look like :
import java.awt.Dialog;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
public class Numbers {
static public void main(String[] args) {
boolean bKeepGoing = true;
String sNumber;
int iNumber;
int iDialogResult;
JOptionPane.showMessageDialog(null,"Hello!", "Welcoming title!" , JOptionPane.PLAIN_MESSAGE);
while(bKeepGoing){
sNumber = JOptionPane.showInputDialog(null, "Enter a number between 0 and 9999 :", "Input a number!",JOptionPane.QUESTION_MESSAGE);
try{
iNumber = Integer.parseInt(sNumber);
JOptionPane.showMessageDialog(null, getString(iNumber) , "Here it is!" , JOptionPane.INFORMATION_MESSAGE);
iDialogResult = JOptionPane.showConfirmDialog(null, "Would you like to continue?", "Keep going?", JOptionPane.YES_NO_OPTION);
if(iDialogResult == JOptionPane.NO_OPTION){
bKeepGoing=false;
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Ooops we got an error!\n" + e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
}
}
JOptionPane.showMessageDialog(null, "Good bye stranger!", "Cya", JOptionPane.INFORMATION_MESSAGE);
}
public static String getString(int n){
String s = "";
if(n == 0){
s += "Zero";
return s;
}
if(n < 0){
s += "Minus ";
n *= -1;
}
if(n/1000 > 0){
s+= getNumber(n/1000) + "Thousand ";
}
n -= (n/1000)*1000;
if(n/100 > 0){
s+= getNumber(n/100) + "Hundred ";
}
n -= (n/100)*100;
if(n/10 > 1){
s+= getDecade(n/10);
n -= (n/10)*10;
if(n/1 > 0){
s+= getNumber(n/1);
}
}
else if(n/10 == 1){
if(n > 13){
s += getNumber(n-10).trim() + "teen";
}
else{
switch (n) {
case 10:
s += "Ten";
break;
case 11:
s += "Eleven";
break;
case 12:
s += "Twelve";
break;
case 13:
s += "Thirteen";
break;
}
}
}
else{
n -= (n/10)*10;
if(n > 0){
s+= getNumber(n);
}
}
return s;
}
public static String getNumber(int n){
String s = "";
switch (n) {
case 9:
s= "Nine ";
break;
case 8:
s= "Eight ";
break;
case 7:
s= "Seven ";
break;
case 6:
s= "Six ";
break;
case 5:
s= "Five ";
break;
case 4:
s= "Four ";
break;
case 3:
s= "Three ";
break;
case 2:
s= "Two ";
break;
case 1:
s= "One ";
break;
}
return s;
}
public static String getDecade(int n){
String s;
switch (n) {
case 9:
s= "Ninety ";
break;
case 8:
s= "Eightty ";
break;
case 7:
s= "Seventy ";
break;
case 6:
s= "Sixty ";
break;
case 5:
s= "Fifty ";
break;
case 4:
s= "Fourty ";
break;
case 3:
s= "Thirty ";
break;
case 2:
s= "Twenty ";
break;
default:
s = "";
break;
}
return s;
}
}