Topic
4 replies Latest Post - ‏2012-07-11T10:32:04Z by willey
needhelp111
needhelp111
1 Post
ACCEPTED ANSWER

Pinned topic new to jave need help

‏2010-07-23T21:20:58Z |
I need help to modify the code and put an if statement so it allow only the odd values in the array A to print please help thanks naomi
int i;
int[] A ={2,1,7,8,10};
for (i=0; i<A.length; i++)
A[i] =2*i;
for (i=0; i<A.lenght; i++)
system.out.println(a[i] + " ");
system.out.println() ;
Updated on 2012-07-11T10:32:04Z at 2012-07-11T10:32:04Z by willey
  • Caleb_Payne
    Caleb_Payne
    9 Posts
    ACCEPTED ANSWER

    Re: new to jave need help

    ‏2010-08-05T23:06:26Z  in response to needhelp111
    A couple of pointers:
    
    
    
    for(
    
    int i = 0; i < myArray.length; i++) 
    { 
    // insert your logic here 
    }
    


    Pointer #2:
    
    System.out.printf(
    "3 is %s\n", (3 % 2 == 1 ? 
    "Odd" : 
    "Even"));
    
  • KamronK.
    KamronK.
    3 Posts
    ACCEPTED ANSWER

    Re: new to jave need help

    ‏2012-04-03T00:12:45Z  in response to needhelp111
    It would be easier for you if your:

    int[] A

    could be a:

    float[] A

    Because then when you are in the for loop your "if" statement could be:

    String tester = "" + (A[i] / 2);
    if (tester.contains(".0")){
    //Then it is even
    } else {
    //It is odd
    }
    I really hope that helps.
  • KamronK.
    KamronK.
    3 Posts
    ACCEPTED ANSWER

    Re: new to jave need help

    ‏2012-04-03T00:16:16Z  in response to needhelp111
    Better yet:

    String tester = "" + (A[i] / 2);
    if (tester.endsWith("0")){
    //It is even
    } else {
    //It is odd
    }

    This way it is not broken by decimal numbers (like other floats)

    =D

    Again, I hope this helps.
  • willey
    willey
    4 Posts
    ACCEPTED ANSWER

    Re: new to jave need help

    ‏2012-07-11T10:32:04Z  in response to needhelp111
    Making your web access secure using SSL Certificate is a right choice and Choosing the right Certificate Authority for SSL Certificate is tough one ,here it is Comodo is the only Certificate authority which gives full support from initializing till installing your SSL Certificate.