473,461 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

what is the logic

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[ ] args) {
  2.       int x = 5;
  3.       while (x > 1) { 
  4.           x = x + 1;
  5.           if (x < 3) {
  6.                System.out.println("small x");
  7.           }
  8.       }
  9.  }

the output of the program is smallx but how?
Apr 28 '10 #1
2 1237
Dheeraj Joshi
1,123 Expert 1GB
I will suggest you to put the print statement for x inside the if loop

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[ ] args) {
  2. int x = 5;
  3. while (x > 1) { 
  4. x = x + 1;
  5. if (x < 3) {
  6. System.out.println(x);
  7. System.out.println("small x");
  8. }
  9. }
  10. }
  11.  
This will print
Expand|Select|Wrap|Line Numbers
  1. -2147483648
  2. small x
  3.  
While loop will be running continuously and if condition will be failing till x becomes -2147483648. when x reaches -2147483648, it prints small x and comes out of the loop.

Regards
Dheeraj Joshi
Apr 28 '10 #2
thanks a lot
Apr 28 '10 #3

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

Similar topics

2
by: Mike Hennessy | last post by:
I'm looking for people's opinions and feedback regarding the design of the application tier, and how to best logically separate out the Data Access from the Business Object's. Per the Microsoft...
0
by: news.microsoft.com | last post by:
I have a collection of pages and user controls in a separate project that I compile and use in a sub folder of a all my projects. This is a collection of re-usable modules that I use on every...
3
by: davidw | last post by:
I created my own WebControl, I am thinking a way to put some logics in the class to a seperated class, and it will be accessed by all instances of my WebControl, the idea is that the class doesn;t...
5
by: Claire | last post by:
I've explained the problem in the following code snippet. I want to share single functions for use by several data types. In this function I call different functions to fill out the original object...
3
by: RAJESH | last post by:
I am working with c# and asp.net in developing web applications, iam using ..netframework 1.1 ,i want to know what is the need of 3-tier or 4-tier architecture in our application development.what...
3
by: Ben Becker | last post by:
I am trying to build a custom crosstab type of grid where I take some items in a data grid and based on the content of the current item compared to the previous item, determine if a new row in a...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: fiona | last post by:
FOR IMMEDIATE RELEASE Catalyst release low cost logic processing tool 87% of defects in software are errors in logic Yucca Valley, CA, September 2006 - Catalyst Development Corporation,...
23
by: marora | last post by:
I keep hearing about not to use 'go_to' in your code. However, I don't know what's the reasoning behind it? Can any one here shed some light? Thanks in advance, Manish
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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 projectplanning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.