Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Replicator{
  5.     public static String monista(String word, int num) {
  6.         String empty = "";
  7.         if (num <= 1){
  8.             return empty;
  9.         }
  10.         if (num == 1){
  11.             return word;
  12.         }
  13.         else {
  14.             return (word + ", " + monista(word, num - 1));
  15.         }
  16.     }
  17.  
  18.     public static void main(String [] args){
  19.         Scanner reader = new Scanner(System.in);
  20.         System.out.println("Hello! I replicate strings.");
  21.         System.out.println("Please, enter a string:");
  22.         String word = reader.nextLine();
  23.         System.out.println("Please, enter the number of replications:");
  24.         int num = reader.nextInt();
  25.         String replicated = monista(word, num);
  26.         if (replicated == ""){
  27.             System.out.println("Error!");
  28.         } else {
  29.             System.out.println(replicated);
  30.         }            
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement