- class BreakWithLabelDemo {
-
public static void main(String[] args) {
-
-
int[][] arrayOfInts = { { 32, 87, 3, 589 },
-
{ 12, 1076, 2000, 8 },
-
{ 622, 127, 77, 955 }
-
};
-
int searchfor = 12;
-
-
int i;
-
int j = 0;
-
boolean foundIt = false;
-
-
search:
-
for (i = 0; i < arrayOfInts.length; i++) {
-
for (j = 0; j < arrayOfInts[i].length; j++) {
-
if (arrayOfInts[i][j] == searchfor) {
-
foundIt = true;
-
break search;
-
}
-
}
-
}
-
-
if (foundIt) {
-
System.out.println("Found " + searchfor +
-
" at " + i + ", " + j);
-
} else {
-
System.out.println(searchfor
-
+ " not in the array");
-
}
-
}
-
}
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.
2 1387
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
Thanks,
I got it now.
regards,
Neha
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
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
|
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...
|
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 =...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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: 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...
| |