Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Why does this return a false?
if (!member.getPermissions().contains(Permission.ADMINISTRATOR) || !member.getId().equals(UniversalVariables.DJZK)) {
eb = EmbedMaker.embedBuilderDescription(MessageSender.noPermission);
channel.sendMessage(eb.build()).queue();
return;
}
You need to be a bit more specifi CH as far as i can tell you say in the if-Statement:
if you have NOT permission ADMINISTRATOR OR Are NOT user A then Do smoething
This is logically equivalent to if you are both ADMINISTRATOR AND user A then DON‘T run the if statement.
So you probably are the said user A and have the said permission.
your return; statement has no argument so it returns "nothing"! This may be 0 which is interpreted as False.
So the logic or is irrelevant to the return value. So return(true); would return logic true when the if condition is true.
Nathan's Answer was right. Usage of Morgan's Rule.
if(!(member.getPermissions().contains(Permission.ADMINISTRATOR) || member.getId().equals(UniversalVariables.DJZK))){
eb = EmbedMaker.embedBuilderDescription(MessageSender.noPermission);
channel.sendMessage(eb.build()).queue();
return;
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is what I want to happen:
char mirrorWords='x'||'w';
what I want to do with this is:
mirrorWords=='u'
returns false.
and
mirrorWords=='x'
returns true.
and
mirrorWords=='w'
returns true.
if this is possible how do I do it? And if not, well... thank you for your time.
update: I don't know why this is closed... I already accepted an answer.
No you cannot store more than one character in a single variable. However when you do the comparison you can do:
mirrorWords == 'w' || mirrorWords == 'x'
which will return true if either conditions is true, which sounds like what you want
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Suppose that i have given below syntax:
Boolean isCapital = city.isCapital();
String isCapitalName;
if(isCapital == null) {
isCapitalName = "";
}
Means that i do not want else condition in my short for(The header of this blog) then what should be the syntax.
I want to minimize the use of if else condition in my project so that i want to use on liner if else.
Please guide.
You can set isCapitalName like so:
String isCapitalName = isCapital == null ? "" : null;
This has an identical behavior to your current code. It sets it to:
an empty string "" if isCapital == null
null by default
Edit taking into account #khelwood's comment:
The default value of an uninitialized local variable is not actually null, but it would cause an error if you used it in your code. I'm not sure why you would leave it uninitialized, however -- you probably want to choose a default value to put in the second clause of the ternary.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
That is the method I've tried. If they type Yes with caps and yes without it will still count and it does not work.
Scanner in = new Scanner(System.in);
String In = in.next();
if (In.equals("Yes") & (In.equals("yes")) {
// Do this
}
else {
// Do this
}
Yes, you can do what you're talking about. This is the syntax:
if (In.equalsIgnoreCase("yes")) {
//Do something
}
It is also possible to do this:
if (In.equals("YES") || In.equals("yes")) {
//Do something
}
However, there's no reason to with the String method's case-insensitive comparison, see above. You really don't want to use your current syntax for 3 reasons: (1) AND operator is &&. Your operator is bitwise AND but this is not a bitwise operation. (2) It's not possible to have a string be equal to more than one thing, so use OR not AND if you're going that way. (3) Watch your parentheses, they're off.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm not sure if I should ask about it ,but it just makes me curious (*I found it on my colleague's codes , but not exactly same ):
Under what circumtance that "true" bellow is accepted ? * Why this line is considered as useless that's what i'm asking for explanation as I don't understand !! I meant it means same like if (true==true) , but why if( ) always true for default circumtance?
public class UnknownChecking {
public static void main(String[] args) {
if(true){
System.out.println("something");
}
}
}
* It will print "something" .
true is always true. That is called tautology.
It's the same as writing System.out.println("something"); without the if statement.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Question:i just want to ask 2 question, if i write 2 below codes in java then which one is faster in terms of cpu cycles and why? Someone told me that 1st option is not correct in terms of cpu cycle because in that 2 conditions are checked i.e if and !
boolean flag = true;
//OPTION ONE
if(!flag) {
//error
} else {
//got the answer
}
//OPTION TWO
if(flag) {
//got the answer
} else {
//error
}
There is no practical difference on a modern JVM implementation.
The compiler will do the right thing, don't worry about it. In fact, if it can prove that flag always has a constant value of true at compile time it will eliminate the check and the unreachable branch entirely.