Register for free, and make this box disappear!

Welcome to the BF Forums! Register Now, It's Free!


Welcome to the BF Forums; your source for the latest video game news, strategies, discussions, and resources. Join over 66,000 like-minded gamers to chat about your interests in our community.

You are currently viewing the forums as a guest user, which limits your access to certain content, contests, downloads, and more. By joining our free community, you will be able to respond in discussions/articles, contact members privately (PM), participate in regular-scheduled contests, see less advertisements, and have access to many other features. Registration is quick, easy, and completely free.



Have your questions answered. Share your thoughts about a topic. Take 2 minutes, Register Now!
BattleForums.com Forums > General > Chit Chat

We're Half-Way There!! - BF Lotto: $50 Ebay or Amazon Gift Card - A Single Click is All It Takes...

Reply
 
Thread Tools Display Modes
Old 02-13-2008, 07:52 PM   #1 (permalink)
BattleForums Junior Member
 
DarkGhost368's Avatar
 
Join Date: Sep 2004
Age: 18
Posts: 115
Help Me With Java

Hey, I was coding this do-while loop and it doesn't work properly. everytime I enter a valid entry (N,S,E,W) it repeats the loop. Can someone explain this to me? I'm still new too java.

Code:
char heading;
do{
	System.out.println("Enter Direction (N,E,S,W)");
	heading = IN.readLine().toUpperCase().charAt(0);
}while((heading != 'S')||(heading != 'E')||(heading != 'S')||(heading != 'E'));
DarkGhost368 is offline   Reply With Quote
Beitrag Sponsored Links

__________________
Ads suck! Take 2 minutes to register for your free account, and GET RID OF THESE ADS!
Old 02-13-2008, 07:55 PM   #2 (permalink)
 
Guest's Avatar
 
Join Date: Jun 2003
Location: New york
Age: 22
Posts: 3,917
Re: Help Me With Java

Pm
x42bn6

ITS HIS ****ING JOB
__________________
Quote:
Originally Posted by lol
Hello,

You've been warned for spamming and posting useless content in The Asylum.
Quote:
Originally Posted by lollercoasterzster
does anyone else remember that time darkmatter flipped out and got himself banned because he is a cryspacing little whiner and now he tries to act all cool like it didnt happen but everyone remembers it did and it was the dumbest reason to get banned too because he said he was all stressed out bcuz his parents were divorcing and his first instinct was to go cry about it on the internet forum but now that i think about it it actually makes some sense bczu he spent so much time here it was more impornatt to him than rl? tbh i think he is noob imo.
Last edited by TrongaMonga on 10-5-04 at 9:37 PM

Last worshipped by Zsquared on today at right now
Guest is offline   Reply With Quote
Old 02-14-2008, 12:54 PM   #3 (permalink)
BattleForums Senior Member
 
SweatyOgre's Avatar
 
Join Date: Jun 2003
Location: PA
Age: 20
Posts: 3,112
Re: Help Me With Java

Replace your "or" conditionals with "and" conditionals. (&&)

Whenever you have a code problem just look at it logically. Your loop will repeat if the user hasn't entered N or S or E or W. So it will repeat unless the user has entered N, S, E and W which isn't possible.

Comp Sci major here, your whalecum.

Quote:
Originally Posted by Guest View Post
Pm
x42bn6

ITS HIS ****ING JOB
Last I knew he was a student still, so he probably doesn't have a job programming in Java without a degree.
SweatyOgre is offline   Reply With Quote
Old 02-14-2008, 02:30 PM   #4 (permalink)
Aya Matsuura is awesome
 
x42bn6's Avatar
 
Join Date: Nov 2002
Location: Trieste, Friuli-Venezia Giulia
Age: 20
Posts: 15,163
Re: Help Me With Java

Indeed, but I don't need a degree to help, do I?

Why do you need such stupid ways to read a character?

Code:
InputStreamReader reader=new InputStreamReader(System.in);
tmp=reader.read();
ch=(char) tmp;
And the ||s to &&s is correct. By de Morgan's Laws, (heading!='S')||(heading!='E')||(heading!='S')||(h eading!='E')=!((heading=='S')&&(heading=='E')&&(he ading=='S')&&(heading=='E'))=!false=true because heading cannot be multivalued at any one instance. Hence it will loop again, and again, and again, and again, and so on.*
__________________
* IM IN UR WIKI RVRTING UR EDITS
x42bn6 is online now   Reply With Quote
 
Reply

Get rid of all these ads! Take 30 seconds to register.

« Free Pancakes! | Foo Fighters canceled their concert here. »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


All times are GMT -4. The time now is 09:13 PM.



Powered by vBulletin® Version 3.7.2 | Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0