|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Can anyone explain why I can't do this? (Java)
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Networking Nut
![]() |
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();
}
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.
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Networking Nut
![]() |
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.
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||
|
Linux Lobbyist
![]() |
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.
|
|||||||||||
|
|
|
|
|
#4 (permalink) | ||||||||||||||
|
Security Sleuth
![]() |
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:
Proud Member of the Linux Gaming CommunityI am your friend.
|
||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|