Results 1 to 3 of 3

Thread: return{Resolved}

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103

    return{Resolved}

    public int woo(int a){

    int y = 78;

    for(int i=0; i<100; i+10){ //i+10 is invalid
    if (i == a)
    return y;
    }

    return a;

    }

    I want the method to return 'y' if 'a' == 'i'.

    if i == a, will the for loop be stopped (no further loops) and y be returned (ending the method)?
    therefore, if i != a, a will be returned?

    by the way, how do i get the increment of i to be +10 in every pass?
    Last edited by Dilenger4; Sep 5th, 2003 at 12:37 PM.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Code:
    public class X{
      public static void main(String[] args){
    
      for(int i = 0; i <=100; i += 10)  {
        System.out.println(i);
     }
    }

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Code:
     public class X{
       public static void main(String[] args){
    
        int result = woo(52);
        System.out.println(result);
     
     }
    
      public static int woo(int a){
    
        boolean match = false;    
    
        for(int i = 0; i <=100; i += 10){
          if(i == a){
           match  = true;
           break;
         }
        }
        
        int result = match ?  78 : a;
        return result;
      }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width