Computer Science, asked by sunitakoley90, 1 year ago

Write a program in java forming a pattern
12345
2345
345
45
5

Answers

Answered by muakanshakya
21
\Huge\textbf{ANSWER:}

\textsf{\bf{class\:pattern}}
{

\textsf{\bf{public \: static \:void\:main(String\:args[])}}

{

for(int i = 5 ; i>1 ;i--)

{

\large{\textsf{for(int j = 1 ; j\textless= i;j++)}}

{

\textsf{\bf{System.out.print(j);}}


}

j++;

\textsf{\bf{System.out.println();}}

}

}

}//end program

\Large \textbf{Out}\textbf{put}
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
_______________________________
\begin{tabular}{|c|l|} \bf Variable & \bf Description\\ \cline{1-2}int i& to iterate the for $\rm lo op$ \\ & for pattern \\ \cline{1-2}int j & to print the pattern\\ \end{tabular}
_______________________________

\Large{\textbf{Note:}}

print(): It is used to continue the sentence in the same line without changing the line

println(): sentence will start from the next line .
Attachments:

Anonymous: Nice !
Anonymous: but the given pattern is different : \
muakanshakya: yeah!
muakanshakya: i didn't notice it earlier
muakanshakya: =_="
Answered by Anonymous
40

\huge{\textbf{\underline{\underline{CODE}}}}


class pattern

{

public static void main(String args[])

{

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

{

for(int j = i ; j < = 5 ; j++ )

{

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

}

System.out.println();

}

}//end of main

}//end of class


\textbf{\huge{NOTE\::}}


\bigstar \textsf{The pattern is printed by the statement print()}\\\\\bigstar \textsf{The pattern is printed by the j }\textsf{lo}\textsf{op.}\\\\\bigstar \textsf{The line break is given by the word println().}


\underline{\textbf{VARIABLE DESCRIPTION TABLE}}


\begin{tabular}{|c|l|} \textf Variable &amp; \textsf Description\\ \cline{1-2}int i&amp; for-lo}\textsf{op}\\\cline{1-2}int j &amp; for-lo}\textsf{op which prints the pattern}\\ \end{tabular}

Similar questions