Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-15-2008, 01:50 AM
Member
 
Join Date: Sep 2008
Posts: 16
Rep Power: 0
pjr5043 is on a distinguished road
Default how do i make a string return a number?
for example .. how can i edit this code to return a number?
Code:
	String whatIsUp()
	{
		double r = 0;
		int n=0;
		String b = "......";
		r = (Math.random()*10);
		n = (int)r;
		System.out.println("just for you to have an idea of the value of r and n =>>"+ " r="+r+",n="+n);
  		if (n == 0) 
			b = "reading";
  		if (n == 1) 
			b = "talking";
  		if (n == 2) 
			b = "interacting";
  		if (n == 3) 
			b = "wildly coding in Java";
  		if (n == 4) 
			b = "sound asleep while instructor is talking some Java stuff";
		return b;
	}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-15-2008, 03:42 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,481
Rep Power: 8
Fubarable is on a distinguished road
Default
Code:
int whatIsUp()
{
   int n = 0;
   //... lot of stuff
   return n
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-15-2008, 03:51 AM
Member
 
Join Date: Sep 2008
Posts: 16
Rep Power: 0
pjr5043 is on a distinguished road
Default
ok thanks .. i'm trying to call on it in an app but its not working .. when it was a string i would call on it like gr1.participate1() and that would do it, but now since its an int do i need to do something different?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-15-2008, 04:04 AM
Member
 
Join Date: Sep 2008
Posts: 16
Rep Power: 0
pjr5043 is on a distinguished road
Default
nvmd got it .. thank you very much
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-15-2008, 05:18 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Are you trying to return an int value or a string converted into int value number?

If you have solve the problem please mark it as solved.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-15-2008, 05:43 AM
Member
 
Join Date: Sep 2008
Posts: 16
Rep Power: 0
pjr5043 is on a distinguished road
Default
i solved it .. thank you
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-15-2008, 05:56 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Ok, mark it as solved.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert String number to int gabriel New To Java 5 08-02-2009 04:46 PM
the number of occurrences of each alphabetical letter in the string. masaka New To Java 20 05-14-2008 10:42 AM
HashMap String Return kizilbas1 New To Java 1 03-10-2008 04:34 AM
make a variable name from a string? Kinnikinnick New To Java 3 11-13-2007 04:54 PM
Will make a pyramid of some kind out of a number romina New To Java 1 08-07-2007 06:20 AM


All times are GMT +2. The time now is 04:23 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org