Ques:
A young man and his grandfather meet an old lady. The old lady asks the young man: "How old are you?"
The man answers :
If you divide my age by 3 the remainder will be 1
If you divide my age by 4 the remainder will be 2
if you divide my age by 5 the remainder will be 4
What is my age?
Ans:
package extrial;
public class ExTrial {
public static void main(String[] args) {
int loop=0;
int ouloop=0;
int oloop=0;
int iloop=0;
int i=0;
int j=3;
int k=4;
int NUM=100;
int[] cnums=new int[NUM];
int[] cnumo=new int[NUM];
int[] cnumi=new int[NUM];
//outer loop
while(loop<100){
if (i%j==1){
cnums[ouloop]=i;
if (cnums[ouloop]%k==2){
cnumo[oloop]=i;
if(cnumo[oloop]%5==4){
cnumi[iloop]=i;
iloop++;
}
oloop++;
}
ouloop++;
}
loop++;
i++;
}
System.out.println("the age is: "+cnumi[0] );
}
}
}
No comments:
Post a Comment