Quantcast
Channel: Crunchify
Viewing all articles
Browse latest Browse all 1037

Java: Given a Non-Empty String Like -Code- Return a String Like -CCoCodCode-

$
0
0

Java String Splosion Python Equivalent Java: Given a Non Empty String Like  Code  Return a String Like  CCoCodCode

Here is a very simple Java Program equivalent to Python’s string_splosion function.

package com.crunchify.tutorials;

/**
 * @author Crunchify.com
 * 
 */

public class CrunchifyStringSplosion {
	public static void main(String[] args) {
		System.out.println("Result: " + occurance("Code"));
	}

	public static String occurance(String str) {
		String temp = "";
		for (int i = 0; i < str.length() + 1; i++)
			temp += str.substring(0, i);
		return temp;
	}
}

Result:

Result: CCoCodCode

The post Java: Given a Non-Empty String Like -Code- Return a String Like -CCoCodCode- appeared first on Crunchify.
Author: Arpit Shah.


Viewing all articles
Browse latest Browse all 1037

Trending Articles