series-2

 5 4 3 2 1

5 4 3 2

5 4 3

5 4

5

// shortcut way

class series

{

public static void main(String args[])

{

for(int r=1;r<=5;r++)  //  r- for row

{

for (int c=5 ; c>=r ; c--)// c- column

{

System.out.print(c+ "  ");

}

System.out.println() // to come to next line

}

}

}


// common way

class series

{

public static void main(String args[])

{

int a=5, d=5;   //  a- means first value  d- means how many element in first line

for(int r=1;r<=5;r++)

{

a=5;

for (int c=1 ; c<=d ; c++)

{

System.out.print(a+ "  ");

a--;

}

d--;

System.out.println() // to come to next line

}

}

}


Comments

Popular posts from this blog