954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

im like LITERALLY NEW TO JAVA HELP!!!!

guys i cant understand or even think of how i can start my program. I should input a number and convert it in words ..its so hard for me to understand how to do this because like what i have said im NEW here thank you
so i need to convert a number into words from "1" to "10,001" it will take me months if i will type it over and over again so is there any other way? this is what i did :

String words;
	     int num = Integer.parseInt(JOptionPane.showInputDialog("Enter Number"));
	      		       
	     if (num == 1) {
			            words = "one";
			        } else if (num == 2) {
			            words = "two";
			        } else if (num == 3) {
			            words = "three";
			        } else if (num == 4) {
			            words = "four";
			        } else if (num == 5) {
			            words = "five";
			        } else if (num == 6) {
			            words = "six";
			        } else if (num == 7) {
			            words = "seven";
			        } 
			        
			        else {
			            words = "unidentified";
			        }
			        JOptionPane.showMessageDialog(null, "Translation in words = " + words);
	}

}

thank you guys hope u can help me.

Ms New to Java
Junior Poster
135 posts since Jan 2012
Reputation Points: 10
Solved Threads: 1
 

you may be literally new to Java, but you are also literally ignoring help that's been given in the other thread about this application.
have you changed anything yet? implemented the arrays as suggested?
don't start a new thread, continue in the other one with the hints you were given, or pretty soon you'll find not many members will be as willing to help any more.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 
you may be literally new to Java, but you are also literally ignoring help that's been given in the other thread about this application. have you changed anything yet? implemented the arrays as suggested? don't start a new thread, continue in the other one with the hints you were given, or pretty soon you'll find not many members will be as willing to help any more.

sir i did..what i did is this:

String[] arrWords = {"one","two","three","four"};

int arrNumbers= Integer.parseInt(JOptionPane.showInputDialog("Enter Number"));

JOptionPane.showMessageDialog( null,"translation"+arrWords);


}

}


and it does have some errors please dont laugh at me with my errors...ive been really trying to figure out how and i appreciate ur help...thank you sir ur suggestions are really helpful and i also searched on google some of the things that u said like that array but thats what i get. im sorry sir if im slow :(

Ms New to Java
Junior Poster
135 posts since Jan 2012
Reputation Points: 10
Solved Threads: 1
 

if you try to print an object (an array is always an object) you'll only print a reference to that object, in the form of [I@3e25a5, so you may think that it is an error, but it isn't.
first thing you do, you read your number.
after which, you find in arrNumbers the index of that number
then, you print the word that can be found on the same index in arrWords.

do you know how to use the index of an array?

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

Please search forum this was already discussed multiple times (last time no longer then few weeks). Secondly use of if/else for every check is mad house use array

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

if you try to print an object (an array is always an object) you'll only print a reference to that object, in the form of [I@3e25a5, so you may think that it is an error, but it isn't. first thing you do, you read your number. after which, you find in arrNumbers the index of that number then, you print the word that can be found on the same index in arrWords.

do you know how to use the index of an array?


no sir i dont have any idea on how to use array and index because we are still on our discussion on if else statements .. :( so i dont know what that is im sorry :(

Ms New to Java
Junior Poster
135 posts since Jan 2012
Reputation Points: 10
Solved Threads: 1
 

@Ms New to Java
1)Multiposting not welcome!
2) Use code tags when posting any code such as [code]YOUR CODE HERE[/code]
3) Thread closed. For further discussion follow this thread

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: