Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 09-26-09   #1 (permalink)
Networking Nut
 
Bviper's Avatar
 
intel nvidia

Join Date: May 2006
Posts: 490

Rep: 41 Bviper is acknowledged by some
Unique Rep: 34
Trader Rating: 0
Default Can anyone explain why I can't do this? (Java)

Code:
while(choice !=("T"||"F"))
	{
	        System.out.println("This program can only be run with a file to copy. Would you like to continue?");
		System.out.println("Enter T to continue, or F to exit the program.");
		choice = userDecision.next();
	}
What I get from the compiler:

Prog1.java:20: operator || cannot be applied to java.lang.String,java.lang.String while(choice !=("T"||"F"))



I mean it makes sense to me... while this string literally does not equal T or F, then continue to try and get it to.

System: The cubed quad
CPU
Intel Q9450
Motherboard
Abit IP35 Pro
Memory
4 x 2 GB G.Skill PC21000
Graphics Card
EVGA 8800GTS 512/XFX 8600GT
Hard Drive
4 Seagate 320 16mb Raid 1+0
Sound Card
Audigy 2 ZS Platinum
Power Supply
Silverstone Decathalon 750 watts
Case
Lian Li PC-7B PLUS II
CPU cooling
Swiftech Apogee
GPU cooling
Stock
OS
Vista Ultimate 64bit
Monitor
WH 22"/Hanns G 19"/VS 17"
Bviper is offline Bviper's Gallery   Reply With Quote
Old 09-26-09   #2 (permalink)
Networking Nut
 
Bviper's Avatar
 
intel nvidia

Join Date: May 2006
Posts: 490

Rep: 41 Bviper is acknowledged by some
Unique Rep: 34
Trader Rating: 0
Default

Code:
 while((choice.equalsIgnoreCase("T") || choice.equalsIgnoreCase("F"))== false)
	{
		System.out.println("This program can only be run with a file to copy. Would you like to continue?");
		System.out.println("Enter T to continue, or F to exit the program."); choice = userDecision.next();
	}

Well, that's what I ended up going with. It's better because it ignores case, but I still would like to know if there's any more compact method.

System: The cubed quad
CPU
Intel Q9450
Motherboard
Abit IP35 Pro
Memory
4 x 2 GB G.Skill PC21000
Graphics Card
EVGA 8800GTS 512/XFX 8600GT
Hard Drive
4 Seagate 320 16mb Raid 1+0
Sound Card
Audigy 2 ZS Platinum
Power Supply
Silverstone Decathalon 750 watts
Case
Lian Li PC-7B PLUS II
CPU cooling
Swiftech Apogee
GPU cooling
Stock
OS
Vista Ultimate 64bit
Monitor
WH 22"/Hanns G 19"/VS 17"
Bviper is offline Bviper's Gallery   Reply With Quote
Old 09-26-09   #3 (permalink)
Linux Lobbyist
 
hybrid-kernel's Avatar
 
amd nvidia

Join Date: Jun 2008
Posts: 250

Rep: 35 hybrid-kernel is acknowledged by some
Unique Rep: 32
Trader Rating: 0
Default

can't do choice !=("T"||"F") because you can't compare strings with basic operators, ("T"||"F") cannot be evaluated as a boolean and unless choice is boolean, you can't compare it to one.

you'd probably have better luck with chars. don't know what approach to use though.
__________________
~Linux Enthusiast
Don't click here, I mean it. You've been warned.

System: Fission
CPU
Athlon 64 x2 4200+ @ 2.8Ghz (255 x 11)
Motherboard
Asus M2A-VM
Memory
4gb (Kingston 4x 1gb)
Graphics Card
XFX 8800gt 512mb (725/1900)
Hard Drive
250gb WD + 500gb ext
Power Supply
450w
CPU cooling
Stock
GPU cooling
Stock (Zalman)
OS
Sidux Ουρανός amd64
Monitor
Samsung Syncmaster 216BW
hybrid-kernel is offline hybrid-kernel's Gallery   Reply With Quote
Old 09-27-09   #4 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: egypt
Posts: 1,267

Rep: 67 Pooping^fish is acknowledged by some
Unique Rep: 62
Trader Rating: 3
Default

Javas funny, and I dont know of anything better than what youve implemented.
Ill let you know though that chars are generally referenced using single quotes.
Such as:
Code:
blah[x] = 'x';
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: ragequit
CPU
Q9550 4ghz @ 1.25v
Motherboard
Asus Max 2 formula
Memory
OCZ LV blade 1:1 950mhz
Graphics Card
8800gtx 610/1ghz
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
leetlinucks
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Reply


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



All times are GMT -5. The time now is 12:43 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.12718 seconds with 8 queries