Printing name in the form of a triangle
import javax.swing.JOptionPane;
import javax.swing.Spring;
import org.apache.commons.lang3.StringUtils;
public class Triangle
{
public static void main(String[] args)
{
String res="";
String fin="";
String a=JOptionPane.showInputDialog(null,"What is your name ?");
if ( a.length() % 2 != 0)
{
a=a+"_";
}
for (int len=1 ; len<= a.length() ; len++)
{
res=StringUtils.leftPad(a.substring(0, len), a.length())+"\n";
fin=fin+res;
}
JOptionPane.showMessageDialog(null, fin);
}
}
import javax.swing.Spring;
import org.apache.commons.lang3.StringUtils;
public class Triangle
{
public static void main(String[] args)
{
String res="";
String fin="";
String a=JOptionPane.showInputDialog(null,"What is your name ?");
if ( a.length() % 2 != 0)
{
a=a+"_";
}
for (int len=1 ; len<= a.length() ; len++)
{
res=StringUtils.leftPad(a.substring(0, len), a.length())+"\n";
fin=fin+res;
}
JOptionPane.showMessageDialog(null, fin);
}
}
No comments:
Post a Comment