Results 1 to 7 of 7
  1. #1
    pjr5043 is offline Member
    Join Date
    Sep 2008
    Posts
    16
    Rep Power
    0

    Default how do i make a string return a number?

    for example .. how can i edit this code to return a number?
    Java 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;
    	}

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Java Code:
    int whatIsUp()
    {
       int n = 0;
       //... lot of stuff
       return n
    }

  3. #3
    pjr5043 is offline Member
    Join Date
    Sep 2008
    Posts
    16
    Rep Power
    0

    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?

  4. #4
    pjr5043 is offline Member
    Join Date
    Sep 2008
    Posts
    16
    Rep Power
    0

    Default

    nvmd got it .. thank you very much

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    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.

  6. #6
    pjr5043 is offline Member
    Join Date
    Sep 2008
    Posts
    16
    Rep Power
    0

    Default

    i solved it .. thank you

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. how to convert String number to int
    By gabriel in forum New To Java
    Replies: 5
    Last Post: 08-02-2009, 03:46 PM
  2. Replies: 20
    Last Post: 05-14-2008, 09:42 AM
  3. HashMap String Return
    By kizilbas1 in forum New To Java
    Replies: 1
    Last Post: 03-10-2008, 03:34 AM
  4. make a variable name from a string?
    By Kinnikinnick in forum New To Java
    Replies: 3
    Last Post: 11-13-2007, 03:54 PM
  5. Will make a pyramid of some kind out of a number
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •