Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hi can you help me recreate this program in typescript code: import java.util.Scanner; 21 20 /** 19 * Pattern 18 */ 17 public class Pattern

hi can you help me recreate this program in typescript

code:

import java.util.Scanner; 21 20 /** 19 * Pattern 18 */ 17 public class Pattern { 16 /** 15 * Function finds the index of a number, using Binary Search recursively. 14 * 13 * @param number 12 * @return printPattern 11 */ 10 public static String printPattern(int number) { 9 if ( number < 1) 8 return ""; 7 else { 6 if(number >= 5) 5 return printPattern(number - 1) + " " 4 + number +printPattern(number - 1) + " " + " "; 3 else 2 return printPattern(number - 1) + " " 1 + number + printPattern(number - 1); 31 } 1 }

/** 17 * The starting main() function. 16 * 15 * @param args No args will be used 14 */ 13 public static void main(String[] args){ 12 Scanner sc = new Scanner(System.in); 11 System.out.println("Enter a number between 1 to 15"); 10 int number = sc.nextInt(); 9 if(number < 1 || number > 15){ 8 System.out.println("Error: Worng input"); 7 } else { 6 System.out.println("User input | Program output"); 5 System.out.println( number + " | "+printPattern(number)); 4 3 System.out.println(" "); 2 } 1 } 52 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions