Click here to Skip to main content
16,020,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am reading from excel.Can someone explain this loop in detail :-what will be the output for this

for (int i= 1 ; i < totalNoOfRows; i++) {
for (int j=0; j < totalNoOfCols; j++) {
arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
}
}

What I have tried:

for (int i= 1 ; i < totalNoOfRows; i++) {
for (int j=0; j < totalNoOfCols; j++) {
arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
}
}
Posted
Updated 22-Feb-17 1:02am
Comments
[no name] 22-Feb-17 6:47am    
There will not be any output. You should run the code in your debugger, step by step, and you will see exactly what is happening.
Abigaill 9-Nov-18 3:34am    
You should try out this Excel library for Java, it provides a simple means for reading Excel files, check it out.

If the code is working (that is: it is able to read data from Excel without an error), your arrayExcelData is probably filled with the string data from the rows 1 to totalNoOfRows (excluding the first row which might be a header row) and columns from index 0 to totalNoOfCols.

You did not specify what kind of functions you are using but I guess they are jxl.
Then see Sheet getCell(int, int)[^] and Cell getContents()[^].
 
Share this answer
 
Quote:
I am reading from excel.Can someone explain this loop in detail :-what will be the output for this
Why not ask the author ?

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900