Language – Java/C++ | Type – Problem (Code) | Last date 19-Apr-2009 12:00 p.m. IST | Points 5
I was attending a session the other day and the instructor was adamant that the Java language is pretty cool (which it is – I just love it). To illustrate his point he referred to the fact that we cannot use a ‘=’ sign in a ‘if condition’ causing problems like it did in C/C++.
"Of course you can use a single = to in a 'if condition'. I have seen that happen so many times" I blurred out. "No way" he challenged. Care to take up this challenge for me?
Got an answer? Why don’t you leave it here.
Showing posts with label Puzzles. Show all posts
Showing posts with label Puzzles. Show all posts
Wednesday, April 15, 2009
Wednesday, March 25, 2009
Puzzle 10 – Go forth and multiply.
Language – Java | Type – Problem (Code) | Last date 29-Mar-2009 | 12:00 p.m. IST | Points 5
Here I was quietly doing my work (Ok ok I was playing mind sweeper) when my manager comes to me and ask me to write a code that could multiple two floating point numbers for him. Why he does not use a calculator, I cannot imagine, but I started to write the program anyway.
As you know my key board gives me a lot of trouble and the ‘*’ sign does not work. Help me out folks!
Write a program to multiple two floating point numbers.
Twist: Do not use the “*” (multiplication sign) in the entire program.
Got an answer? Why don’t you leave it here.
Here I was quietly doing my work (Ok ok I was playing mind sweeper) when my manager comes to me and ask me to write a code that could multiple two floating point numbers for him. Why he does not use a calculator, I cannot imagine, but I started to write the program anyway.
As you know my key board gives me a lot of trouble and the ‘*’ sign does not work. Help me out folks!
Write a program to multiple two floating point numbers.
Twist: Do not use the “*” (multiplication sign) in the entire program.
Got an answer? Why don’t you leave it here.
Labels:
Floating Point Arithmetic,
Java,
Programming,
Puzzles
Sunday, March 22, 2009
Puzzle 9 – Double Fun
Language – Java | Type – Concept | Last date 25-Mar-2009 9:00 p.m. IST | Points 2
The other day I started writing code for a mission critical application – and I needed to loop over. Bored with the standard integer way of looping I decided to be adventurous and used doubles instead. Can you tell me if I am doing something wrong out here?
The other day I started writing code for a mission critical application – and I needed to loop over. Bored with the standard integer way of looping I decided to be adventurous and used doubles instead. Can you tell me if I am doing something wrong out here?
1 package com.twisters;
2 public class MyDouble {
3 public static void main(String[] args) {
4 for(double d = 0.0; d != 1.0; d = d + 0.1){
5 System.out.println("Doing a strategic thing here…");
6 }
7 }
8 }
Got an answer? Why don’t you leave it here.
Labels:
Double,
Java,
Primitive Type,
Programming,
Puzzles
Wednesday, March 18, 2009
Puzzle 8 – Misleading Count.
Language – Java | Type – Concept | Last date 22-Mar-2009 12:00 p.m. IST | Points 2
This is why ‘i’ am so important …
This is why ‘i’ am so important …
Got an answer? Why don’t you leave it here.
package com.twisters;
public class MyLoop {
public static void main(String[] args) {
for(int i=0;i<10;i++){
for(i=0;i<5;i++){
System.out.println("Testing");
}
}
}
}
Sunday, March 15, 2009
Puzzle 7 – Add and Subtract
Language – Java | Type – Problem (Code) | Last date 18-Mar-2009 9:00 p.m. IST | Points 5
It’s easy to add up. Subtracting however is another ball game …
Write a program to subtract two floating point numbers.
Twist: Do not use the “-” (minus sign) in the entire program.
Got an answer? Why don’t you leave it here.
It’s easy to add up. Subtracting however is another ball game …
Write a program to subtract two floating point numbers.
Twist: Do not use the “-” (minus sign) in the entire program.
Got an answer? Why don’t you leave it here.
Wednesday, March 11, 2009
Puzzle 6 – Overloaded
Language – Java | Type – Concept | Last date 15-Mar-2009 12:00 p.m. IST | Points 2
Have you ever felt over loaded with work? Here is something to cheer you up …
Have you ever felt over loaded with work? Here is something to cheer you up …
package com.twisters;Got an answer? Why don’t you leave it here.
class Base{}
public class Child extends Base{
public boolean equals(Base b){
return false;
}
public static void main(String[] args) {
Base base;
Child child;
child = new Child();
base = child;
if(child.equals(base))
System.out.println("Child Equals Base");
if(base.equals(child))
System.out.println("Base Equals Child");
}
}
Labels:
Inheritance,
Java,
Polymorphism,
Programming,
Puzzles
Sunday, March 8, 2009
Puzzle 5 – The Sign
Language – Java | Type – Concept | Last date 11-Mar-2009 9:00 p.m. IST | Points 2
Too many signs spoil the code …
Got an answer? Why don’t you leave it here.
Too many signs spoil the code …
package com.twisters;
public class Signs{
public static void main(String[] args) {
int result;
int a = 5, b =1;
result = a---b;
System.out.println("Value of a is : " + a);
System.out.println("Value of b is : " + b);
System.out.println("Value of result is : " + result);
}
}
Got an answer? Why don’t you leave it here.
Labels:
Arithmetic,
Java,
Operator,
Programming,
Puzzles
Wednesday, March 4, 2009
Puzzle 4 – The Swap
Language – Java/C++ | Type – Problem (Code) | Last date 8-Mar-2009 12:00 p.m. IST | Points 5
Swapping can be easy, but this is the hardest swap ever!
Write a program that swaps two numbers.
Twist: Do not use “=” (equal sign) in entire program.
(Hard isn't it? )
Got an answer? Why don’t you leave it here.
Swapping can be easy, but this is the hardest swap ever!
Write a program that swaps two numbers.
Twist: Do not use “=” (equal sign) in entire program.
(Hard isn't it? )
Got an answer? Why don’t you leave it here.
Labels:
Java,
Programming,
Puzzles,
Swap,
Swapping
Sunday, March 1, 2009
Puzzle 3 – Inheritance
Language – Java | Type – Concept | Last date 4-Mar-2009 09:00 p.m. IST | Points 2
Inheritance can be fun, especially if you get loads of money. But then again Inheritance can be a big headache. Especially in Java, if you inherit more that you can chew…
Inheritance can be fun, especially if you get loads of money. But then again Inheritance can be a big headache. Especially in Java, if you inherit more that you can chew…
package com.twisters;Got an answer? Why don’t you leave it here.
class Base{
public void baseCall(){
test();
}
public void test(){
System.out.println("Function Test in Base Executed");
}
}
public class Child extends Base {
public static void main(String[] args) {
Base baseRef = new Child ();
baseRef.baseCall();
}
public void test(){
System.out.println("Function Test in Child Executed");
}
}
Wednesday, February 25, 2009
Puzzle 2 –Divide and (Multiply) Rule
Language – Java | Type – Concept | Last date 4-Mar-2009 9:00 p.m. IST | Points 2
I always considered myself to be good at algebra. I had no problems with equations, trigonometry and multiplication. But it takes Java to make simple algebra tricky. Do you know what this code does and why?
I always considered myself to be good at algebra. I had no problems with equations, trigonometry and multiplication. But it takes Java to make simple algebra tricky. Do you know what this code does and why?
package com.twisters;
public class MulAndDiv {
public static void main(String[] args) {
double result;
result = 2.0*2/4+2/4;
System.out.println("The result is : "+ result);
}
}
Sunday, February 22, 2009
Puzzle 1 – Hello World
Language – Java/C++ | Type – Problem (Code) | Last date 25-Feb-2009 9:00 p.m. IST | Points 5
Well here I was trying to write my first Java code. I was pretty excited. I started typing just to realize that the ‘W’ key on my keyboard wasn’t working. That’s when I had to write my Hello World code without a ‘W’. Do you think you can help me out with this?
Write a program to print “Hello World”.
Twist: Do not use the letter ‘W’ or ‘w’ in the source code.
Pretty simple stuff, but then it’s just the beginning of a long journey …
Well here I was trying to write my first Java code. I was pretty excited. I started typing just to realize that the ‘W’ key on my keyboard wasn’t working. That’s when I had to write my Hello World code without a ‘W’. Do you think you can help me out with this?
Write a program to print “Hello World”.
Twist: Do not use the letter ‘W’ or ‘w’ in the source code.
Pretty simple stuff, but then it’s just the beginning of a long journey …
Subscribe to:
Posts (Atom)