Computer Science, asked by maharshiguin100, 1 year ago

How can i print the letter 'M' and 'G' in star pattern in java using loops or other such method ?

Answers

Answered by Shivaya1
0
class CharPattern1 {    public static void main(String[] args) {        char ch = 'A';        for (int i = 1; i <= 5; i++) {            for (int j = 1; j <= i; j++) {                System.out.print(ch);                ch++;            }            System.out.println();        }    }} import java.util.Scanner; public class CharPattern2 {     public static void main(String[] args) {        System.out.println("Enter a String: ");        Scanner sc = new Scanner(System.in);        String s = sc.nextLine();        sc.close();                char [] a=s.toCharArray();        for (int i = 0; i < a.length; i++) {            for (int j = 0; j <= i; j++) {                System.out.print(a[j]);            }            System.out.println();        }    } }  
Similar questions