Computer Science, asked by Anonymous, 5 hours ago

program to generate the following output :

5 55 555 5555 55555 555555

expecting wonderful answers from brainly computer master :)

Answers

Answered by anindyaadhikari13
6

Solution:

The given problem is solved using language - Java.

import java.util.*;

public class Series{

   public static void main(String s[]){

       System.out.print("Enter n: ");

       int n=(new Scanner(System.in)).nextInt();

       for(int i=1,a=5;i<=n;i++,a=a*10+5)

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

   }

}

Logic:

  1. Accept the limit from the user, say n.
  2. Initialise a = 5
  3. Display the value of a.
  4. Multiply a by 10 and add 5.
  5. Repeat steps 3 and 4 n times.

See attachment for output.

Attachments:
Answered by Oreki
6

\textbf{Program}

   \texttt{public class Pattern \{}\\\texttt{\hspace{1.5em} public static void main(String[] args) \{}\\\texttt{\hspace{3em} for (int i = 1; i &lt; 6;)}\\\texttt{\hspace{4.5em} System.out.print("5".r\symbol{101}peat(i++) + " ");}\\\texttt{\hspace{1.5em} \}}\\\texttt{\}}

\textbf{\symbol{79}utput}

   \texttt{5 55 555 5555 55555}


anindyaadhikari13: Nice approach.
Similar questions