Computer Science, asked by sanjana188, 11 months ago

WAP in java using scanner to print pattern...................................................

Attachments:

Answers

Answered by Anonymous
2
import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); //Printing upper half of the pattern for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println();

tamoghnadbpc: u hv to use the values of A,B,C,D,E to generate the pattern
sanjana188: fine
Answered by muakanshakya
7
\Huge\textbf{\underline{\underline{Answer;}}}

\textbf{\textsf{import\:java.util.*;}}

\textbf{\textsf{class \:pattern}}

{

\textbf{\textsf{Scanner\:sc\:=\:new\:Scanner(System.in);}}

\textbf{\textsf{System.out.println("Enter\:the\:no\:of\:terms\:=\:");}}

int n= sc.nextInt();

{

for(int i=n ; i>=0; i--)

{

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

{

\textbf{\textsf{System.out.print((char)(j+65));}}

}

\textbf{\textsf{System.out<br />println();}}

}

}

}

The required pattern:

ABCDE
ABCD
ABC
AB
A
_____________________________
\begin{tabular}{|c|l|} \bf Variable &amp; \bf Description\\ \cline{1-2}int i&amp; to iterate the for $\rm lo op$ \\ &amp; for pattern purpose \\ \cline{1-2}int j &amp; to iterate and print the pattern\\ \end{tabular}
________________________

\textbf{\huge{Note:}}

●println():- For printing the sentence from next line

●print():- To continue the sentence in the same line
Similar questions