Display data in right angle triangle with side towards right
I have used "StringUtils.leftPad" which is present inside " org.apache.commons.lang3.StringUtils; "
1. Download common/common-lang3.jar.zip( 613 k) from http://www.java2s.com/Code/Jar/c/Downloadcommonlang3jar.htm
2.Extract Jar files and the files to your Package in Eclipse.
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
public class Triangle_right
{
{
public static void main(String[] args)
{
String sRes="";
String sData=JOptionPane.showInputDialog("enter data");
for (int i=1 ; i<=sData.length();i++)
{
sRes=sRes+StringUtils.leftPad( sData.substring(0, i), sData.length())+"\n";
}
System.out.print(sRes);
}
{
String sRes="";
String sData=JOptionPane.showInputDialog("enter data");
for (int i=1 ; i<=sData.length();i++)
{
sRes=sRes+StringUtils.leftPad( sData.substring(0, i), sData.length())+"\n";
}
System.out.print(sRes);
}
}
No comments:
Post a Comment