Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post

    Checking variables shortcut

    I have this sample snippet of mine, and want to know if I can shorten the if statement; that is checking the integer, for example, to not write d== or || multiple times.
    PHP Code:
    import jahava.jarava;
    public class 
    test
    {
    int d=0;
    while(
    timeIncreases())
    {
    d++
    }
        if (
    d==7||d==14||d==21||d==27||d==33||d==38||d==43||d==47||)
    new 
    Obaj(3,3).display();

    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You could create an array of int, and use a search on it:
    PHP Code:
    int[] iaCheck = new int[]{714212733384347);
    if (
    Arrays.binarySearch(iaCheckd) >= 0)
    {
        
    // is true.

    This is similar to PHP:
    PHP Code:
    $iaCheck = array(714212733384347);
    if (
    array_search($d$iaCheck) !== false)
    {


  • #3
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post
    Thanks again Fou-Lu; I'll try and see if I can implement this function correctly, hopefully there will be no problems.

    EDIT: I compiled it and there was an error saying that it couldn't recognize Arrays.binarySearch in addition to syntax error(s). I'll have to find another way to make the array work, and without having to visibly add imported files. Moreover I forgot that this is a reference class, and not the main method.

    [IMG]http://www.codingforums.com/data:image/gif,GIF89a%12%00%12%00%B3%00%00%FF%FF%FF%F7%F7%EF%CC%CC%CC%BD%BE%BD%99%99%99ZYZRUR%00%00%00%FE%01%02 %00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%04%14%00%FF%00%2C%00%00%00%00 %12%00%12%00%00%04X0%C8I%2B%1D8%EB%3D%E4%00%60(%8A%85%17%0AG*%8C%40%19%7C%00J%08%C4%B1%92%26z%C76%FE %02%07%C2%89v%F0%7Dz%C3b%C8u%14%82V5%23o%A7%13%19L%BCY-%25%7D%A6l%DF%D0%F5%C7%02%85%5B%D82%90%CBT%87%D8i7%88Y%A8%DB%EFx%8B%DE%12%01%00%3B[/IMG]
    Last edited by Taro; 12-14-2012 at 03:35 AM. Reason: There's an un-intended glitch in this post that I would like to remove.
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Import the java.util.Arrays.
    I also have a syntax error, you need to change the end of the array to a closing brace, not a bracket.


  •  

    Tags for this Thread

    Posting Permissions

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