hi
i am beginner in java and i need help with programining ,Please if you could suggest me some sites where i can see some solved examples of codes as well as i need code for following
55551
55512
55123
51234
12345
I need a code to make above mentioned , in nested loop form.
thanks and regards
8 2849
hi
i am beginner in java and i need help with programining ,Please if you could suggest me some sites where i can see some solved examples of codes as well as i need code for following
55551
55512
55123
51234
12345
I need a code to make above mentioned , in nested loop form.
thanks and regards
Try to figure out the regularity: Java counts starting at zero, so there are lines
0, 1, 2, 3 and 4. On line i (i in [0,4]) there are i+1 '5' characters followed by the
digits i+1, ... i+2 etc. until 5 characters are printed.
That observation leeds to a nested loop: the outer loop simply counts from 0 to 4.
The inner loop also counts from 0 to 4 and uses an if statement to decide whether
or not to print 5s or simply increasing digits 1, 2, 3 etc. Of course there are many
ways to solve this little puzzle.
kind regards,
Jos
hi
i am beginner in java and i need help with programining ,Please if you could suggest me some sites where i can see some solved examples of codes as well as i need code for following
55551
55512
55123
51234
12345
I need a code to make above mentioned , in nested loop form.
thanks and regards
i'll give you an example, i hope my fellow TSDN's members wont flame at me---> -
<%@ page import="java.util.*" %>
-
<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c' %>
-
<html>
-
<head><title></title></head>
-
<body>
-
<%
-
ArrayList arrList = new ArrayList() ;
-
ArrayList subList1 = new ArrayList() ;
-
ArrayList subList2 = new ArrayList() ;
-
ArrayList subList3 = new ArrayList() ;
-
-
subList1.add( "subList1_1" ) ;
-
subList1.add( "subList1_2" ) ;
-
subList1.add( "subList1_3" ) ;
-
subList1.add( "subList1_4" ) ;
-
-
subList2.add( "subList2_1" ) ;
-
subList2.add( "subList2_2" ) ;
-
subList2.add( "subList2_3" ) ;
-
subList2.add( "subList2_4" ) ;
-
-
subList3.add( "subList3_1" ) ;
-
subList3.add( "subList3_2" ) ;
-
subList3.add( "subList3_3" ) ;
-
subList3.add( "subList3_4" ) ;
-
-
arrList.add( subList1 ) ;
-
arrList.add( subList2 ) ;
-
arrList.add( subList3 ) ;
-
-
request.setAttribute("myList", arrList );
-
%>
-
-
<c:forEach var='mainItem' items='${requestScope.myList}' varStatus='status'>
-
Main ArrayList Count: <c:out value='${status.count}'/> <br />
-
<c:forEach var='subItem' items='${mainItem}'>
-
<font color="red">Names: <c:out value='${subItem}'/></font>
-
<br />
-
</c:forEach>
-
-
</c:forEach>
-
</body>
-
</html>
-
i'll give you an example, i hope my fellow TSDN's members wont flame at me---> -
<%@ page import="java.util.*" %>
-
<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c' %>
-
<html>
-
<head><title></title></head>
-
<body>
-
<%
-
ArrayList arrList = new ArrayList() ;
-
ArrayList subList1 = new ArrayList() ;
-
ArrayList subList2 = new ArrayList() ;
-
ArrayList subList3 = new ArrayList() ;
-
-
subList1.add( "subList1_1" ) ;
-
subList1.add( "subList1_2" ) ;
-
subList1.add( "subList1_3" ) ;
-
subList1.add( "subList1_4" ) ;
-
-
subList2.add( "subList2_1" ) ;
-
subList2.add( "subList2_2" ) ;
-
subList2.add( "subList2_3" ) ;
-
subList2.add( "subList2_4" ) ;
-
-
subList3.add( "subList3_1" ) ;
-
subList3.add( "subList3_2" ) ;
-
subList3.add( "subList3_3" ) ;
-
subList3.add( "subList3_4" ) ;
-
-
arrList.add( subList1 ) ;
-
arrList.add( subList2 ) ;
-
arrList.add( subList3 ) ;
-
-
request.setAttribute("myList", arrList );
-
%>
-
-
<c:forEach var='mainItem' items='${requestScope.myList}' varStatus='status'>
-
Main ArrayList Count: <c:out value='${status.count}'/> <br />
-
<c:forEach var='subItem' items='${mainItem}'>
-
<font color="red">Names: <c:out value='${subItem}'/></font>
-
<br />
-
</c:forEach>
-
-
</c:forEach>
-
</body>
-
</html>
-
try to manipulate with this example.
I understand the concept, jos,but I can't write in code, I just wrike like that
class NestedLoop {
public static void main (String [] a) {
int n=5, i, j;
for (i = 1; i <=n; i++) {
Then I don't know how to write.Can help me how to write in code?
I understand the concept, jos,but I can't write in code, I just wrike like that
class NestedLoop {
public static void main (String [] a) {
int n=5, i, j;
for (i = 1; i <=n; i++) {
Then I don't know how to write.Can help me how to write in code?
Write the loops that Jos was explaining above.
Write the loops that Jos was explaining above.
... or go fancy and write a single loop: -
private static void square(int n) { // assume 1 <= n <= 9
-
char[] line= new char[n];
-
Arrays.fill(line, (char)('0'+n));
-
String s= new String(line);
-
for (int i= 1; i <= n; i++)
-
System.out.println(s= (s+i).substring(1));
-
}
-
You can't turn this in because there's no nested loop :-P
kind regards,
Jos
.....
You can't turn this in because there's no nested loop :-P
kind regards,
Jos
Yep, but keep the ideas in mind for the time when you are no longer writing code for school only.
Thank you ,you all help me a lot!!!!!!!!!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: kbass |
last post by:
I am new to Python and I am attempting to retrieve data from a database and
I would like to place this data into a nested dictionary. After placing the
data into a dictionary, I would like to loop...
|
by: chad |
last post by:
I am writing a program to do some reliability calculations that
require several nested for-loops. However, I believe that as the
models become more complex, the number of required for-loops will...
|
by: Neptune |
last post by:
Hello.
I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)"
(Sam's series), and for nested loops, he writes (p116) "It's often
necessary to create a loop even when you are...
|
by: nimmi_srivastav |
last post by:
Below you will see an example of a nested conditional expression that
this colleague of mine loves. He claims that it is more efficient that
a multi-level if-else-if structure. Moreover, our...
|
by: Peter Olcott |
last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html
The above link shows that C# is 450% slower on something as simple as a nested
loop....
|
by: so.intech |
last post by:
for example,
ret = 0;
for(i=0; i<3; i ++;)
{
for(j=0; j<4; j++;)
{
for(k=0; k<3; k++;)
{
for(m=0; m<4; m++;)
{
|
by: GY2 |
last post by:
I writing some documentation and I want to describe a common code structure
which is used to step through all the items in a collection (e.g. each file
in a subdirectory) while applying more and...
|
by: Jan Schmidt |
last post by:
Hi,
in a nested do-while-loop structure I would like to "continue" the outer
loop. With goto this should be no problem in while-loops. However, for
do-while I cannot get it to work (without a...
|
by: Sheldon |
last post by:
Hi,
Can anyone help with this problem with setting up nested structures
and initializing them for use.
I have created several structs and placed them in a super struct that
I will then pass to...
|
by: Andreas Eibach |
last post by:
Hi again,
one of the other big woes I'm having...
typedef struct perBlockStru /* (structure) Long words per block
*/
{
unsigned long *lword;
} lwperBlockStru_t;
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |