public void draw(int x, int y) { // move down y lines for ( int i = 0; i <= y; i
ID: 3634427 • Letter: P
Question
public void draw(int x, int y)
{
// move down y lines
for ( int i = 0; i <= y; i++)
System.out.println();
// for each row
for (int len = 1; len<=rows; len++)
{
//indent x spaces
for (int i = 1; i <= x; i++)
System.out.print(' ');
for (int j = 1; j <= (len-1); j++)
System.out.print(character);
System.out.println();
}
}
} #
##
###
######
#########
Explanation / Answer
Please Rate:Thanks
//This code help you to print left triangle
import java.util.Scanner;
public class leftTriangle {
int rows;
char character;
public void draw(int x, char character)
{
for(int i=1;i<=x;i++)
{
for(int j=i;j<x;j++)
System.out.print(' ');
for(int k=1;k<=i;k++)
System.out.print(character);
System.out.println();
}
}
public static void main(String[] args){
leftTriangle l=new leftTriangle();
Scanner input=new Scanner(System.in);
System.out.println("Enter number of rows ");
int rows=input.nextInt();
System.out.println("Enter special Charecter ");
char c=input.next().charAt(0);
l.draw(rows,c);
}
}
--------------------------------------------------------------------------
Output:
Enter number of rows
4
Enter special Charecter
#
#
##
###
####
BUILD SUCCESSFUL (total time: 4 seconds)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.