View Single Post
Old 20-08-07, 03:26 PM   #4 (permalink)
sk_kireeti
Super Moderator
 
sk_kireeti's Avatar
 
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117
Thanked 241 Times in 198 Posts
Thanks: 117
Thanked 241 Times in 198 Posts
Blog Entries: 4
Rep Power: 51 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
Re: Puzzle asked in Oracle : What is the number?

Here is the java program which does the same....


/* **************************************************** */
/* here is the puzzle for which the code finds solution.*/
/* */
/* There are 5 digits (XXXXX) in a number and each digit*/
/* of the number has a specific meaning. */
/* */
/* 1 st digit -> represents number of 0's in the number */
/* 2 nd digit -> represents number of 1's in the number */
/* 3 rd digit -> represents number of 2's in the number */
/* 4 th digit -> represents number of 3's in the number */
/* 5 th digit -> represents number of 4's in the number */
/* */
/* What is the number? */
/* **************************************************** */

public class puzzle
{

static int a[]=new int[5];

static int getNumberCount(int searchnumber)
{
int count=0;
for(int i=0;i<5;i++)
{
if(a[i]==searchnumber)
count++;
}
return count;
}

public static void main(String args[])
{
for(a[0]=1;a[0]<=4;a[0]++)
for(a[1]=0;a[1]<=4;a[1]++)
for(a[2]=0;a[2]<=4;a[2]++)
for(a[3]=0;a[3]<=4;a[3]++)
for(a[4]=0;a[4]<=4;a[4]++)
{
if(a[0]==getNumberCount(0) && a[1]==getNumberCount(1) &&a[2]==getNumberCount(2) &&a[3]==getNumberCount(3) &&a[4]==getNumberCount(4))
System.out.println("Number : "+a[0]+a[1]+a[2]+a[3]+a[4]);
}
}
}
__________________
Give 1 cup rice to a hungry Indian just by a mouse click. No money, no form filling, no hassle... Click here for the donation.
sk_kireeti is offline   Reply With Quote