I have a dialog that displays various things depending on state of the application, security for the current user etc.
I am currently passing in several boolean flags and then enabling and/or ... |
While I know that by definition a boolean consists of only two states, true or false. I was wondering what value does a boolean have before it is initialized with one ... |
I noticed the other day that I can call boolean.class, but not integer.class (or on other primitives). What makes boolean so special?
Note: I'm talking about boolean.class, not Boolean.class (which would make ... |
what should the following java code do?
public class foo{
public static void main(String[] args){
boolean mybool=false;
assert (mybool==true);
...
|
I need a mutable boolean field in Java (I will return this field via get* method later and it should be possible to modify this field).
Boolean doesn't work because there are ... |
For e.g,
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
new Boolean(true));
JAXB Tutorial
|
What am I doing wrong here?
I am wanting to display integers from 1-100 who are divisible by either 6 or 7. That's done and working. The next step is ... |
|
I need the java code snippet for the below logic:
Following is a string and I need to validate the string based on the below condition :
"100 or 200 and 345 not ... |
I have to use only Boolean and if statements to determine if a number is between 141 and 185 and whether it is lower or higher than that number. I am ... |
I've seen this before in code, but forgotten it. Basically it toggles a boolean variable. If it's true, it'll set to false and vice-versa. But unfortunately forgot the ... |
I'm getting my feet wet with the Apache Commons CLI library for command-line parsing. It works fine for String-valued options, but I'm not sure how to cleanly handle boolean-valued command-line ... |
There are discussion around Integer vs int in Java. The default value of the former is null while in the later it's 0. How about Boolean vs boolean?
A variable ... |
Ok so lets say I have boolean x = false. If I have a loop that says while (!x) does this mean while x is NOT false (true) or while x ... |
Would like to know which direction player hits terrain tile from (just a simple up/down, left/right). Everything I find is either too simple, or is much more complex and seemingly way ... |
I am doing a project in Java for my COSC 117 class and I get an error on my code saying that my boolean type of "done" is never read in. ... |
which one is better in Java code style?
boolean status = true;
if(!status) {
//do sth
} else {
//do sth
}
or
if(status == false) {
//do sth
} else {
//do sth
}
... |
Given two events with integer start and end times, E1 = (s1, e1), E2 = (s2, e2), implement a quick boolean check to see if the events overlap.
I have the solution, ... |
I don't really know how to exactly ask that questing but I hope the title says it already.
I am searching for a way (a framework / lib) which provides an ability ... |
My program keeps on getting the red lines of death for the bigNum variable. I am trying to test to see if its in the boundary. My program sucks as you ... |
Why is this value always true? I just can't figure out how to have a boolean that "blinks" every second.
long millis = System.currentTimeMillis();
boolean blink = (Math.floor(millis/1000 + 0.5)==Math.floor(millis/1000));
|
I found the below paragraph in SCJP 6.0 book. What does it mean by the last statement.Which book to read about how these variables are actually stored in memory?. Thanks a ... |
Why private Boolean shouldDropTables; assigns true by default to the variable instead of NULL like when doing private Integer anInteger;
Asking because I am fixing someone else code where there ... |
private static final Pattern namePattern =
Pattern.compile("[a-zA-Z0-9_-]{3,12}");
if (player.getName().length() < 3 ||
player.getName().length() > 12 ||
...
|
I have the following Java code:
String p = "seven";
String q = "teen";
p + q == "seventeen";
Why does the last line return false and not true?
|
This is kind of a weird question. I'd like to write a Java function that will either return true or false. It will ALWAYS return either true or false for the ... |
I came across the following program
class Boolean {
public static void main(String argv[]) {
boolean x;
x ...
|
Often a class has to be configured using a number of boolean options. What are recommended ways in Java to specify execution configurations?
I can think of 4 ways how options can ... |
import java.util.Scanner;
public class EP59
{
public static void main(String[] args)
...
|
Is it possible to assign some kind of variable that value of it would change the condition of a comparison? I would like dynamicly change the condition so that it would ... |
I cannot figure out how to prove an existence is true or not;
static boolean existsx(double p1x, double p2x,double[] varray) {
boolean foundx = false;
int ...
|
The other day in a forum I was having a discusion about primitive booleans data types. And one guy said that in ALL languages true internally (or natively) is treated like ... |
rooky13 I am working on an assignment for my class (don't worry you're not doing my homework for me). I want to have a method that asks the user a yes/no ... |
I want to parse a string into a boolean value and I implemented this script .. public static void test_lang_boolean(){ System.out.println("boolean false from string "+Boolean.parseBoolean("Boolean.FALSE")); System.out.println("boolean true from string "+Boolean.parseBoolean("Boolean.TRUE")); } ... |
Why you want to scan a boolean value? I suspect your input string is something like "0001001". Consider it as string and convert it down to integer array and calculate according ... |
When I run this code the value of the boolean snare is correctly reset from true to false, but the if test ignores this and executes the code inside the if test. This is the code as shown on page 44 of Head First Java, so it should work. Please assist. Steve Janvrin. class DrumKit { boolean tophat = true; boolean ... |
|
package beans; public class UserFormBean { String userId = ""; String username = ""; String password = ""; String email = ""; String contactNumber = ""; String locationId = ""; String status = ""; boolean online = false; String dateCreated = ""; public UserFormBean() { } public String getContactNumber() { return contactNumber; } public void setContactNumber(String contactNumber) { this.contactNumber = contactNumber; ... |
Hi, I am writing these lines from Java API HttpSession getSession() Returns the current session associated with this request, or if the request does not have a session, creates one. HttpSession getSession(boolean create) Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session. I am unable to ... |
All of the comparison operators (==, !=, >, ...) are binary operators, meaning they operate on two arguments only. To compare more than two arguments, you need to use the logical operatores "and" ("&&") and "or" ("||") . Here's one example to get you going.// Returns true if x is between 5 and 10, inclusive. return x >= 5 && x ... |
|
In the app I'm working on, we have a table class that displays data. The user can load and reload data at various times, calling the table's load() method. I need to do one bit of logic ONLY on the first time load() is called. I'm considering using a boolean flag so I can check whether or not it's the first. ... |
Hi Recently read in kathy sierra that " byte is 8 bit long ... short 16 bit ... etc ... depth of a boolean, is virtual-machine dependent.' " but i what i will like to know is ... how is boolean virtual machine dependent ?? tried googling for it .. no help yet! |
|
Hi justin, here's an overview of the Java operators in general and the precedence rules: operators For conditional operators like && or || there's a special feature called short-circuiting or short circuit evaluation. This means that the expression is only evaluated until the result is clear. For example for "A && B" it's sufficient for the whole expression to be false ... |
|
46. Boolean coderanch.com |
|
48. boolean coderanch.comAdding to what Marilyn has said here's some code: boolean a,b; int j,k; // give a,b and j,k appropriate values int x = j | k; // perform bitwise-or of j,k boolean y = a | b; // perform logical-or of a,b: checks both a and b to make decision. // j || k is not valid because operands must be ... |
I have a program in which a user buys an item at a store. I have the user input the itemName, quantity, unitPrice, and whether it is taxable or not in a String which is tokenized into four parts, delimited by the "|" character. Example: itemName|quantity|unitPrice|N The N or n in the fourth token tells whether the purchase is taxable. How ... |
The value of the assignment expression "a = true" is true -- it assigns "true" to "a" and returns the value "true". So it's as if you had written "if (true)". The fact that assignment expressions have a value is what makes it possible to write statements like "i = j = k = 0;" which is interpreted as "i = ... |
I'm making a program to output any prime number between 100 and 200 for my programming lesson. Now, I'm stuck. It seams everything would be working fine except for one error. In the end: { if (i/num = svar) System.out.println(+svar); else System.out.print(""); } it won't recognize the "/", saying that Task4.java [12:1] unexpected type required: variable found : value if (i/num ... |
52. Boolean coderanch.comHi Linnea, boolean is a primitive datatype of Java that can have one of only 2 possible values: 1. true 2. false Other than these, it is not legal to assign any other value to a boolean variable. The following are examples of some legal assignments: boolean x = true; boolean y = false; y = x; // valid since x ... |
hi - thanks for your help on this so far a mis-type " = " for " == ", would be a very simple explanation, but I don't think I did have reviewed an earlier example I was working on and this is a little more of the code to put it in context public void testName(Member member){ boolean nameExists = ... |
|
import java.util.Scanner; public class Lab14 { public static void main (String[] args) { String weather; int temp; boolean rain = true; Scanner scan = new Scanner(System.in); System.out.println("Is it raining? (yes or no)"); weather = scan.nextLine(); System.out.println("What is the temperature outside?"); temp = scan.nextInt(); if(weather == "yes") rain = true; if((temp >= 60 && temp < 80) && rain) System.out.println("Please visit our ... |
writing a hangman program, but it doesn't seem to be returning the boolean values correctly?? Any help, v. much appreciated! Thanks! for(int i = 0; i < 20 ; i++) { boolean found = false; while(found !=true) { for (int a = 0; a < word.length; a++) { if (attempt == word[a]) { dashes[a] = (char)attempt; rightGuess++; } } if(rightGuess==0) { ... |
Hey all, I have tried everything i can think of to make this go. I am trying to hide the mines with this one line.(it's in bold) I keep getting error messages that state || cannot be applied to a boolean. any help would be appreciated. thanks public class App { public static void main(String[] args) { Game game = new ... |
58. boolean coderanch.com |
I understand that Boolean is a class and boolean is of type primative? Looking at the following method declaration: public Boolean withdraw (amount double) { return x; } should it therefore not be declared as: public boolean withdraw (amount double) { return x; } Which means the first method declaration was a typing error i.e. using a capital B in stead ... |
I am confused on how to evaluate a Boolean expression. Take for example P && Q || !P && !q Okay, I was under the impression ! has the higher precedence so I would evaluate (!p & !q) first. After asking my professor he said I would evaluate P && Q first if they evaluate to True then the compiler doesn't ... |
I am rather confuse on truth tables or how to create them. Take for example the following code segement public class loop { public static void main (String[] args) { boolean a=false; boolean b=false; boolean c=false; boolean d=false; if(!c || d){ if (a && c){ System.out.println("1"); } else if (b) { System.out.println("2"); } else { System.out.println("3"); } } else if (!c ... |
Originally posted by Niyas Ahmed Sheikh: public class Q4 { public static void main(String args[]) { int i=3; System.out.println(getBoolean() ? i = 2 * i++ : i++ + ++i); } public static boolean getBoolean() { if((int) (Math.random() * 2) ==0); return false; else return true; } } What is program logic behind the above pgm.In the getBoolean(), we are checking whether ... |
I'm getting a Boolean field, hence getting value as a true, or false. But when, i want to display that I need to display it as a 'Y' or 'N'. In the getter method for this field, I need to check for true or false. But not sure how will i assign y, n to it Regards, grishma |
I seem to have some problems passing Boolean object by reference. Variable successful does not become false in Main() even though I alter it to that in retrieveNext. Boolean successful = new Boolean(true); while(successful.booleanValue() && counter<15){ System.out.println(TH2.retrieveNext(successful)); counter++; } public double retrieveNext(Boolean successful){ if(channels[currCh].size()>currSampl+1){ currSampl+=1; successful=true; return (Double)(channels[currCh]).get(currSampl); }else{ successful=false; return -1; } } Thanks! [ October 11, 2005: Message edited ... |
|
Hi all I'm trying to write a program that gives the biggest of 3 numbers (integers) and this is the error I get "operator > cannot be applied to boolean, int" Could someone tell me what am I doing wrong? cuz a similar code works for just 2 numbers. Here's the code import acm.program.*; public class ProgramaMayorDe3 extends DialogProgram { public ... |
Hi, Any idea how I can add a boolean method that will simply say whether a video is available or not. I have to admit I'm pretty useless with boolean statements and would appreciate any advice. The program is a simple Video store management program. My current code is as follows, package videos; public class Video { private int days, referenceNumber; ... |
|
In general, you should not worry about exactly how much space is used by fields and objects in Java. It isn't fixed and the language doesn't let you find out (well, maybe there's something in 1.5...?). A big reason for Java's popularity is that it gets you away from worrying about low-level stuff like how the data is actually stored in ... |
Are you sure the first one works? I don't know what you're problem calls for, but there is a constructor of Boolean that accepts a String, and sets the wrapped boolean value to true if the String is equal, ignoring case, to "true", and otherwise sets the wrapped boolean value to false. |
Your question is a bit vague. What do you mean by "catch a change of a boolean expression"? Can you show us some code to explain in more detail what exactly you want to do and what you don't understand? You can use if ... else statements to execute statements depending on if a boolean expression evaluates to true or false. ... |
Hi Keith - Not much more code to provide, sorry. This is a Struts form class which I am trying to fix. The form class is testing for 13 initial values, all which are null. The last test -- && (this.useFooUnique.equals("00") || this.useFooUnique.equals(""))) -- is supposed to catch useFooUnique if it's "00" OR "" ... in this case it's "" and ... |
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ... |
I'll have to guess exactly what the context of that question is, but probably what is meant is that it's not specified how much memory a boolean uses - how much memory a boolean uses can be different on different underlying platforms or JVM implementations. For example, Sun's JVM might use a 32-bit integer for storing booleans in the computer's memory, ... |
'size' of things is java is not really a well defined concept. since java removes pointer arithmatic and the responsibility of memory management from the developer, it's not really needed. As i understand it, the BEHAVIOR of things is defined. a boolean must represent 'true' and 'false'. As to the specifics of HOW that happens, that's up to the folks who ... |
Java is case sensitive -- by this, it is refering to the tokens. The method names, the class names, the variable names, the keywords, etc. Strings are also case sensitive, but so what... strings should always be case sensitive, even if the language is not. It is kinda silly to not be able to write a program that distinguish case of ... |
Hi all, I came across this code but I don't understand it. Especially the boolean part. What does it mean when CR is set to true? Why must we check (CR == false) in the else statement, isn't it redundant? Can we avoid using 'nested if' in this code? How to re-write it? import java.util.*; public class DisplayWords { static Scanner ... |
Hello Antany, thanks for replying. Actually, I wasn't wondering about the precedence. I understand that using braces would mean assigning priority. Actually I didn't frame my question right Let's take this example boolean a = true; boolean b = true; boolean c = true; System.out.println((a=false) && (b=false) && (c=false)); System.out.println(a+" "+b" "+c); will result in false false true false What do ... |
Dear Jigar Boolean is a wrapper Class of primitive boolean, as mentioned by Henry, consideration on using a primitive or a wrapper class depends much on which use you will give to you variable. For example collection classes like List, Set only access classes, they do not access primitives, then if you require that you information be stored on a List ... |
The only place where the size of a boolean is fixed is in serialized form. Internally, a JVM implementation can choose anything they want for a boolean; an int with only values 0 and 1 (or 0 and -1, so that if you flip all bits of true you get false and vice versa), or use one int (32 bits) to ... |
Just running through an exercise for uni. Its saying that I need a bool and program fails. I understand what its asking for, and its refering to a getter. Reason for the program just changing class data. //CommissionEmployee.java public class CommissionEmployee { private String firstName; private String lastName; private String socialSecurityNumber; private double grossSales; private double commissionRate; private double baseSalary; public ... |
82. boolean coderanch.comFirst and foremost -- welcome to JavaRanch! Next off, I'm not sure exactly what it is that you're asking -- to check if the number is odd? that it's divisible by three? both? Next, after clarifying your question, what have you tried so far, and how doesn't it work to your satisfaction? And finally, I'm going to ask that the mods ... |
|
|
Hi there I am new to java, i have some questions. I am writing a program about a race. I have created 2 hierarquies (car) ( race) Car --------- f1Car, nascarCar Track -------- f1Track, ovalTrack my question is i have two methods Track class Start race Finish race Car class my idea is to create a boolean variable: Boolean isRacing = ... |
|
Hi. I started a basic java class and I cannot figure out how to print double quotes around the boolean variable in the code below. Any help would be appreciated. I want the output to look like this: I can get everything except the double quotes. I know you need to use \" somehow but I cannot figure it out. Thanks... ... |
Hi there, I'm very new to Java, and I'm trying to find a solution. I have the user inputting a 6 digit number the last digit is dropped and the 5 digit number is then % 7 to achive a remainder. The remainder and the dropped digit should be the same, if so..a boolean "true" would then be displayed, or false ... |
Hi my program is supposed to play the game Craps 100,000 times. Basically, I have two dice and if the total of them (after being rolled) is 7, the game is one. If it's a 2 or 3, the game is lost. If it's something else I keep rolling until I get the same number or a 7. My program keeps ... |
Hello Everyone! I'm very new to Java but am trying to learn it on my own (while taking a C# class at the same time). I however, believe that I suffer from a clumsy coding style. I designed this class to convert a numerical grade (from 0-4) into a letter grade. The goal of this exercise is not just to convert ... |
Hey there, I'm trying to print out a line so when I have full set to false, it prints out "Box is empty" and when full is set to true, it prints out "Box is full". I'll show you what I have atm, for some reason it just won't work, it's always printing box is empty even when full is set ... |
|
|
Sorry, I'll post in the right sub-forum next time. to webuser: thanks for the post, this really helps. The solution is useful in this case. However, if you use the (a=5) method a number of times in one expression, you can't use this way in java. That would mean you have to make one variable for each boolean you'd want to ... |
thank you guys, I appreciate your help very much. I have another question though: Why are all these handy builtins missing from java? Don't get me wrong, I mean no disrespect for the language, if I did, I wouldn't be trying to learn it.. but every time I try learn how to do something, the answer is always "the long way"!! ... |
I am simply trying to test if two temperatures, one in F and one in C, are the same. But no matter what it comes out true. I am confused on how to get it compare the two values, and do the math to determine if the values are the same. Thanks - Gary :confused: Java Code: public class Temperature { ... |
/* * @(#)BalUitd.java 11/03/15 * * JavaLogo Project * */ import logotekenap.*; public class BalUitd extends TekenApplet { double xverander; double yverander; double xstap; double ystap; int teller; public void initialiseer() { maakTraceMogelijk(); maakAnimatieMogelijk(); xstap=0; ystap=0; xverander=1; yverander=0.5; } public void tekenprogramma() { bal(xstap, ystap, "rood"); } public void bal(double xstap, double ystap, String kleur) { pen.vooruit(ystap+yverander); pen.rechts(90); pen.vooruit(xstap+xverander); pen.links(90); pen.vulAan(kleur); ... |
For my programming 1 class we are learning java and he told us to display this boolean expression p+q((!p||q)&&(!q||p)) this is what i have so far but it keeps giving me an error saying it can't find q...what am i doing wrong? any help is greatly appreciated public class booleans { public static void main(String[] args) { boolean p; boolean q; ... |
Hey, I'm just wondering but how would you write a small piece of code using a boolean that adds up two numbers and tells you if it is true or false on if the sum of the two numbers is even. I know you guys like to see the people asking these kinds of things put up piece of broken code ... |
|