473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

"and" statements

I have only recently begun to use java, so apologies if this is a really stupid question, but how do you go about using and statements.

for example if a user has to input a variable and it has to be between 40 and 60, what would be the code used to do this.

I have been searching around the internet for a while and I can't find the answer anywhere.
Jan 7 '08 #1
5 1160
JosAH
11,448 Expert 8TB
I have only recently begun to use java, so apologies if this is a really stupid question, but how do you go about using and statements.

for example if a user has to input a variable and it has to be between 40 and 60, what would be the code used to do this.

I have been searching around the internet for a while and I can't find the answer anywhere.
Read a turorial; it saves you so much time. The 'and' operator is '&&' and your
boolean expression should look something like this:

Expand|Select|Wrap|Line Numbers
  1. if (input >= 40 && input <= 60) ...
  2.  
kind regards,

Jos
Jan 7 '08 #2
ok thanks very much.

I had been reading various tutorials on the if statement but hadn't been able to find the answer.
Jan 7 '08 #3
BigDaddyLH
1,216 Expert 1GB
ok thanks very much.

I had been reading various tutorials on the if statement but hadn't been able to find the answer.
If you haven't already, add Sun's Java tutorial to your list. It's easy to navigate. For example, I found && in a few seconds:

http://java.sun.com/docs/books/tutor...bolts/op2.html
Jan 7 '08 #4
Ah brilliant, I hadn't found that. Definitely getting bookmarked. I tried && and it isn't working currently, what is wrong with this

Expand|Select|Wrap|Line Numbers
  1.     public void stuff(int input)
  2.  
  3.     {
  4.         if (input >= -40 && <=75) {
  5.            other=input; 
  6.     }
  7.  
  8.         else {
  9.             System.out.println("not valid.");
  10.  
Jan 7 '08 #5
BigDaddyLH
1,216 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. if (input >= -40 && input <=75) 
  2.  
Expressions in Java should be fully spelled out. Java does not use the informal abbreviations people use, for example x < y < z must be written x < y && y < z.
Jan 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Trebor A. Rude | last post by:
I'm new to Perl (although I have about 7 years of C++ experience), and I was just wondering which of these two equivalent statements the group thinks is "better", and why: push @command, map...
1
by: Yannick Turgeon | last post by:
Hello all, I'm using SS 2000 and NT4 (and Access97 as front-end on another server) Well, probably by lack of knowledge about table locks, I don't really know where to start to present this...
2
by: Mike | last post by:
Is there an equivalent in VB.Net or C# of VBScript's "Eval" and "Execute" statements? Thanks, Mike
2
by: Johnny Ljunggren | last post by:
Hello all Just noticed that a testprogram I've made creates a non-conforming XML file. Here's the code (C#) and output: XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent =...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
12
by: Steve Pope | last post by:
Compiling the following works on my system: file main.cpp: #include <iostream> namespace space { int foo; }
11
by: gg9h0st | last post by:
i saw a code refactorying onload event listener window.onloadListeners=new Array(); window.addOnLoadListener=function(listener) { window.onloadListeners=listener; } why declare the...
1
by: arpitjain | last post by:
If there is no difference then why the following statements gives an error. p = 'a';
11
by: S N | last post by:
how to print apostrophe character ' and double quote " in asp using vbscript. my code using response.write replaces " character with inverted question mark. please help
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.