Posts

Showing posts from July, 2016

Integer Overflow

The loop : Inside Out Have a look at below code and guess what could be the output. public class Puzzle26  { public static final int END=Integer.MAX_VALUE; public static final int START=END-100; public static void main(String args[]) { int count = 0; for(int i=START;i<=END;i++) count++; System.out.println(count); } } At a first glance you might think this will print 100, off course because, END is 100 more than START. But look more carefully we are using less than equal to sign. So now you might guess it will print 101. Well, no. This program does not print a thing.  The reason is every integer is less than or equal to Integer.MAX_VALUE. And the moment our program increases Integer.MAX_VALUE there cannot be any value greater than that so it increments the variable i to  -2147483648 , which is the lowest integer value and then keeps incrementing it to  2147483647 i.e. the largest integer value and so on, and it goes

Text To Speech using VB Script

Image
You know the beauty of this program, it dont expect you to download any external .dll or jar or anything, all you have to do is write 4 lines of code and your Text to Speech program is ready, yes you read it right. Lets see how. Open a notepad, Type below code in it : Dim message, sapi message = InputBox("Write something and I will say it for you"+vbcrlf) Set sapi= CreateObject("sapi.spvoice") sapi.Speak message Save the notepad file with .vbs extension , you will notice that the file icon is changed to VB Script icon. N ow open the file again, it will open a window like below.  Type any text in the text box and it will say it for you..Bingo....!