Monday, May 20, 2019

Can you write an algorithm to print the following pattern?

Problem statement:
Given an input string from the console as follows

Sample I/O:

aaaaa, bbbb, cccc, d , f , g , i
Sample O/P:
a5, b4, c4,d1, f1, h1, g1, i1
  1. import java.util.Scanner;
  2. public class SwitchStatement {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.         System.out.println("Enter the pattern.");
  6.         String pattern = sc.nextLine();
  7.         System.out.println(pattern.charAt(0) + "" + pattern.length());
  8.     }
  9. }

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...