Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Replicator{
- public static String monista(String word, int num) {
- String empty = "";
- if (num <= 1){
- return empty;
- }
- if (num == 1){
- return word;
- }
- else {
- return (word + ", " + monista(word, num - 1));
- }
- }
- public static void main(String [] args){
- Scanner reader = new Scanner(System.in);
- System.out.println("Hello! I replicate strings.");
- System.out.println("Please, enter a string:");
- String word = reader.nextLine();
- System.out.println("Please, enter the number of replications:");
- int num = reader.nextInt();
- String replicated = monista(word, num);
- if (replicated == ""){
- System.out.println("Error!");
- } else {
- System.out.println(replicated);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement