Computer Science, asked by ankurmallick35, 5 months ago

Pls solve this JAVA program !​

Attachments:

Answers

Answered by anindyaadhikari13
3

Required Answer:-

Question:

Write a java program for the pattern.

E

ED

EDU

EDUC

EDUCA

EDUCAR

EDUCARE

Solution:

Here is the code.

  1. public class PatternBrainly {
  2. public static void main(String[] args) {
  3. String s="EDUCARE";
  4. int n=s.length();
  5. for(int i=1;i<=n;i++)
  6. {
  7. for(int j=0;j<n-i;j++)
  8. System.out.print(" ");
  9. System.out.println(s.substring(0, i));
  10. }
  11. }
  12. }

Explanation:

Before we start, you must know the syntax of substring function.

Syntax:- <string>.substring(int startIndex, int endIndex)

Let us divide the pattern into two parts - first part for spaces and second part for the spaces.

  • For the first row, you can see that total number of spaces is 6, then for the next row, it is 5 and so on. So, we will print spaces n - i times (n = 7, i=1,2,...)
  • Now, we will use the substring feature. We will display the substring from index 0 to i (where i = 1,2,3,..)
  • In this way, the pattern is solved.

Output is attached for verification.

Attachments:

RockingStarPratheek: Nice
Anonymous: Ossm !!
Anonymous: Amazing..!!
anindyaadhikari13: Thank uh!
Anonymous: wow amingo
Similar questions