Results 1 to 10 of 10
- 06-14-2010, 03:10 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 16
- Rep Power
- 0
help with not equal to operator !=
ok so im having a problem im tryin to write a java program that can work out subnets based on user input but cant get this loop to work like assuming the answer to Q2=128 it will do the if part and run readbit but then the loop starts again instead of continuing :eek: lol any help would be appricated
Java Code://--------------------------------------------subnet class C address---------------------------------------- class subnet{ public static void main (String[] args){ int Q1; int Q2; //----------------------------------------------CLASS C--------------------------------------------- System.out.print ("\nThis is a program that will workout class c addresses for subnetting\n"); System.out.print ("\nplease input the method you wish to workout ip addresses\n"); Q1 = kdr.valgetint("\n1:hosts per subnet\n2:bits borrowed\n3:total subnets\nplease input answer : "); //--------------------------------------------Q1---------------------------------------------------- if (Q1==1) { do{ // ensures that a valid int is got before trying to check it Q2 = kdr.valgetint("\nplease input number of hosts per subnet: "); if(Q2==128 || Q2==64 || Q2==32 || Q2==16 || Q2==8 || Q2==4) { readbit(); } else{ System.out.print ("\nThis is the wrong value it needs to be 128,64,32,16,8,4,2,1"); }; }while(Q2!=128 || Q2!=64 || Q2!=32 || Q2!=16 || Q2!=8 || Q2!=4); } //-------------------------------------------------------------------------------------------------- //--------------------------------------------Q2---------------------------------------------------- if (Q1==2) { do{ Q2 = kdr.valgetint("\nplease input number of bits borrowed: "); if(Q2<=6) { readbit(); } else{ System.out.print ("\nThis is the wrong value it needs to be 1,2,3,4,5,6"); }; }while(Q2<=6); if(Q2==1) { } if(Q2==2) { } if(Q2==3) { } if(Q2==4) { } if(Q2==5) { } if(Q2==6) { } } //-------------------------------------------------------------------------------------------------- } static void readbit() { int count; count = 0; double bit[] ; bit = new double [count]; do{ do{ System.out.print ("\nplease input the value of octet "+(count+1)+":"); bit[count]= Keyboard.readDouble () ; if (bit[count]>=256) { System.out.print ("\nThis is the wrong size for a bit max is 255\n"); } }while(bit[count]>=256); count++; }while(count>3); } }
- 06-14-2010, 03:43 PM #2
Is it one of these:cant get this loop to work
Try debugging the code by adding enough println() statements to show all the values used.do{
do{
System.out.print ("\nplease input the value of octet "+(count+1)+":");
bit[count]= Keyboard.readDouble () ;
if (bit[count]>=256)
{
System.out.print ("\nThis is the wrong size for a bit max is 255\n");
}
}while(bit[count]>=256);
count++;
}while(count>3);
- 06-14-2010, 03:45 PM #3
Why kdr.valgetint
why not scanner, I dont believe valgetint is correct, Shouldn't it be val.getInt()?
what is the value of Q1 and Q2
instead of while, try else if statement. While statement will keep looping until the statement is false.
Java Code:System.out.print ("\nThis is a program that will workout class c addresses for subnetting\n"); System.out.print ("\nplease input the method you wish to workout ip addresses\n"); Q1 = kdr.valgetint("\n1:hosts per subnet\n2:bits borrowed\n3:total subnets\nplease input answer : ");:rolleyes: ~ Sno ~ :rolleyes:
'-~ B.S. Computer Science ~-'
- 06-14-2010, 03:52 PM #4
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
- 06-14-2010, 11:40 PM #5
Member
- Join Date
- Jun 2010
- Posts
- 16
- Rep Power
- 0
this part here
its just this part here that is giving me the prob everything is working otherwise i just want this do while loop to loop unless the value is 128,64,32,16,8,4 and 2 if it does that then i can continue to the printout of the subnet addresses by making all of the answers refer to a printout if thats right lol but ye its the while line thats the prob
Java Code:do{ // ensures that a valid int is got before trying to check it Q2 = kdr.valgetint("\nplease input number of hosts per subnet: "); if(Q2==128 || Q2==64 || Q2==32 || Q2==16 || Q2==8 || Q2==4) { readbit(); } else{ System.out.print ("\nThis is the wrong value it needs to be 128,64,32,16,8,4,2,1"); }; }while(Q2!=128 || Q2!=64 || Q2!=32 || Q2!=16 || Q2!=8 || Q2!=4);
- 06-14-2010, 11:49 PM #6
If Q2 = 128 then Q2 is not equal to 64 etc, so the rest of the tests will always be true.while(Q2!=128 || Q2!=64 || Q2!=32 || Q2!=16 || Q2!=8 || Q2!=4)
You want to continue if Q2 != 128 AND Q2!=64 AND the rest of the list of tests
In other words, fall out of the loop for Q2 equal to any of the values shown in the tests
Did you read what StormyWaters posted?
- 06-14-2010, 11:58 PM #7
Member
- Join Date
- Jun 2010
- Posts
- 16
- Rep Power
- 0
iif i leave it like this then i cant get it to reask the question if the input is incorrect thats what the loop was for how would i fix this bit to validate that it is 128,64,32 etc etc.....
Java Code:Q2 = kdr.valgetint("\nplease input number of hosts per subnet: "); if(Q2==128 || Q2==64 || Q2==32 || Q2==16 || Q2==8 || Q2==4) { readbit(); } else{ System.out.print ("\nThis is the wrong value it needs to be 128,64,32,16,8,4,2,1"); };
- 06-15-2010, 12:03 AM #8
have you tried it? What does it do?i cant get it to reask the question if the input is incorrect
- 06-15-2010, 12:09 AM #9
Member
- Join Date
- Jun 2010
- Posts
- 16
- Rep Power
- 0
hey stormywaters one worked thanks man your a god :)
- 06-15-2010, 12:10 AM #10
Member
- Join Date
- Jun 2010
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
equal() method
By need_helpp in forum New To JavaReplies: 3Last Post: 03-09-2010, 05:57 PM -
ComparisonFailure on equal(to the eye) strings
By staffan in forum New To JavaReplies: 2Last Post: 03-12-2009, 02:57 PM -
Problem using equal() method
By ookie833 in forum New To JavaReplies: 3Last Post: 11-18-2008, 05:19 AM -
checking if there are equal numbers
By nalinda in forum New To JavaReplies: 1Last Post: 11-18-2007, 06:21 AM -
checking if there are equal numbers
By nalinda in forum New To JavaReplies: 0Last Post: 11-18-2007, 02:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks