Posts

Showing posts from June, 2018

Prime String concept and program in Java - Explained

Image
Prime Strings: You must have heard about prime numbers. But have you ever thought about prime string?   It's very simple and interesting. Here's the explanation:-  In computer science, string is sequence of characters.Characters may be alphabets, numbers, punctuation, or special symbols. So any word is a string. for example: "Hello" is a string. Now, what is prime string? A string which cannot be constructed by concatenating two or more than two(multiple) equal strings. Let's have a string "Road" , when we divide "road" into two equal parts we get "ro" and "ad" which are not equal strings. Thus "road" is a prime string . Now let's take a string "baba". By dividing this string into two equal parts we get "ba" and "ba" . Both these strings are equal. So it is not a prime string. Here's a prime string program written in java. It also tells the first h...

Floyd's triangle and reverse Floyd's triangle in java

Image
Hello friends, Let's see what is Floyd's triangle! The concept of Floyd's Triangle  was invented by the computer scientist Robert Floyd. Floyd's Triangle is a right angled triangle filled by natural numbers, which is having n rows. In this triangle nth row will have n natural numbers. So in the first row there will  be only 1 element, that is, 1, in the second row there will be 2 elements next to one, 2 and 3, in third row there will be 3 elements 4,5 and 6. In this way the triangle so formed is called Floyd's Triangle. 1 2 3 4 5 6 7 8 9 10 This is the Floyd's Triangle having 4 rows. Reverse Floyd's Triangle:- Now let us see what is Reverse Floyd's Triangle. It is simply reverse of Floyd's Triangle. The natural numbers are written from end to start. For example, the Reverse Floyd's Triangle for 4 rows will be: 10 9 8 7 6 5 4 3 2 1 This is the Reverse Floyd's Triangle having 4 rows. Here's a program to print Floyd...