473,408 Members | 2,427 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,408 software developers and data experts.

Control flow problem

10
Expand|Select|Wrap|Line Numbers
  1. class BreakWithLabelDemo {
  2.     public static void main(String[] args) {
  3.  
  4.         int[][] arrayOfInts = { { 32, 87, 3, 589 },
  5.                                 { 12, 1076, 2000, 8 },
  6.                                 { 622, 127, 77, 955 }
  7.                               };
  8.         int searchfor = 12;
  9.  
  10.         int i;
  11.         int j = 0;
  12.         boolean foundIt = false;
  13.  
  14.     search:
  15.         for (i = 0; i < arrayOfInts.length; i++) {
  16.             for (j = 0; j < arrayOfInts[i].length; j++) {
  17.                 if (arrayOfInts[i][j] == searchfor) {
  18.                     foundIt = true;
  19.                     break search;
  20.                 }
  21.             }
  22.         }
  23.  
  24.         if (foundIt) {
  25.             System.out.println("Found " + searchfor +
  26.                                " at " + i + ", " + j);
  27.         } else {
  28.             System.out.println(searchfor
  29.                                + " not in the array");
  30.         }
  31.     }
  32. }
Found 12 at 1, 0


Q:-
how come the answer is 1, 0....i think it sld be 0, 1..because 12 is at position 01...where ' i 'stands for row and ' j ' stands for column...please explain me where am i wrong.
Sep 16 '08 #1
2 1387
JosAH
11,448 Expert 8TB
For a two dimensional matrix the first index denotes the rows and the second
one the columns in the rows, so row #0 is { 32, 87, 3, 589 } while row #1 is
{ 12, 1076, 2000, 8 } and row #2 is { 622, 127, 77, 955 }.

Number 12 occurs in row #1 and column #0

kind regards,

Jos
Sep 16 '08 #2
Vneha
10
Thanks,

I got it now.

regards,

Neha
Sep 16 '08 #3

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

Similar topics

1
by: David Chan | last post by:
Hi, I'm trying to use python to create GUI wizards, i.e. sequences of dialog boxes with <BACK and NEXT> buttons. Since I want to re-use some of the dialog boxes in different wizards, I want to...
11
by: Robert Bowen | last post by:
Hello all. I have been given mock-ups (in static HTML) of some pages for a site I am working on. The client would like these pages to look exactly as they do now. The problem is that the content is...
5
by: Miyra | last post by:
Hi. I'm working with an app that uses exceptions for control flow. These are code blocks where exceptions are thrown/caught regularly. A couple hundred exceptions occur per hour and they're caught...
9
by: Alvin Bruney [MVP] | last post by:
Exceptions must not be used to control program flow. I intend to show that this statement is flawed. In some instances, exceptions may be used to control program flow in ways that can lead to...
7
by: Dave | last post by:
Hi, I've read a few contradictory statements on how to do flow control between methods. Main problem is that I've seen recommendations (or "standards") to *not* use exceptions for flow control,...
0
by: Pavan | last post by:
My name is Pavan and I am a software engineer working on ASP .Net web development. Currently I am using .Net 2.0 Professional Edition to develop my web pages. I have a problem
3
by: Steven T. Hatton | last post by:
I'm trying to work out a design for dynamically determining file types, and for generating new files of a given type. I'm curious to know what others think of my current strategy. Is it "so...
2
by: brianlum | last post by:
Hi, I have been looking for a good way to convert python code into a control flow graph. I know of Python functions that will convert an expression into an abstract syntax tree (i.e. ast =...
0
by: jacksparrowminion | last post by:
Hi I want to do a simple control flow graph tool that generates a graph for the user i .e. the circles and arrows that make up a control flow graph used in program testing. Do you have any idea...
3
by: Lowrider | last post by:
I'm new to the VB programming world and am having a problem with flow control. In the code below I check 3 textboxes and display a messagebox if one or more are left blank. The problem lies in that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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 project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.