Pls solve this JAVA program !
Attachments:

Answers
Answered by
3
Required Answer:-
Question:
Write a java program for the pattern.
E
ED
EDU
EDUC
EDUCA
EDUCAR
EDUCARE
Solution:
Here is the code.
- public class PatternBrainly {
- public static void main(String[] args) {
- String s="EDUCARE";
- int n=s.length();
- for(int i=1;i<=n;i++)
- {
- for(int j=0;j<n-i;j++)
- System.out.print(" ");
- System.out.println(s.substring(0, i));
- }
- }
- }
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
Similar questions