Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-13-2012, 10:49 PM   PM User | #1
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
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.
Taro is offline   Reply With Quote
Old 12-14-2012, 12:38 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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)
{

Fou-Lu is offline   Reply With Quote
Old 12-14-2012, 02:50 AM   PM User | #3
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
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]
__________________
Element ID

Webs Support Helper

Your friendly neighborhood Taroman.

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.
Taro is offline   Reply With Quote
Old 12-14-2012, 01:51 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
display, integer, string, variable

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:07 AM.


Advertisement
Log in to turn off these ads.