The Artima Developer Community
Sponsored Link

Java Answers Forum
anyone can explain this program?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ling

Posts: 13
Nickname: ling
Registered: Feb, 2003

anyone can explain this program? Posted: Feb 9, 2003 7:20 PM
Reply to this message Reply
Advertisement
import java.util.List;
import java.util.LinkedList;
import java.util.Iterator;
public class Lab_02

{

public static List getLinesOfText(int m)

{ List lines = new LinkedList();
StringBuffer line = new StringBuffer();
for( int i = 0; i < m; i++ )

{ for( int j = 0; j < m; j++ )
line.append( j < i ? " ": Integer.toString(i%10) );
lines.add(line.toString());
line.setLength(0);
}
return lines;
}

public static void main(String args[])
{
int n = 15;
if( args.length > 0 )
try
{ n = Integer.parseInt(args[0]);
}

catch( NumberFormatException nfe )
{ String msg = nfe.getMessage();

System.out.println(msg);
}
Iterator lineIterator = getLinesOfText(n).iterator();
while(lineIterator.hasNext())
System.out.println(lineIterator.next());
} }

Topic: Errors please help! Previous Topic   Next Topic Topic: To implement a scrollbar in Swing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use