java programming

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

java programming

 
0
  #1
Sep 24th, 2004
Hi!
I can not solve this JAVA problem.
I tried to write:
final int a=100;

int nbr=Input.readInt();// from keyboard

I try to find (nbr*nbr)>a

ex: nbr=11 and 11*11=121
12*12=144
10*10=100

Output must be 121, not 144 but 144 is also >100
thanks
Peter
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 54
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: java programming

 
0
  #2
Sep 24th, 2004
what exactly are you trying to do ... you can use simple if statements to check whether nbr is greater than zero or not.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

Re: java programming

 
0
  #3
Sep 25th, 2004
Hi again!
The Question is:
I try to write a program which find and print out
The smallest n and (n*n) must be greater than a special number.
Ex: n = 11 is the smallest and (n*n) is 121 and is greater than 100.
But n = 12 is also smallest and (n*n) is 144 and is greater than 100.
The program must print out 11 not 12
If we write The number = 500 the out put must be 23 not 24 or 25 ...
I mean n=22 and(n*n=484)
n=23 and (n*n =529) I want this one.
n=24 and(n*n=576)



class Test{

public static void main(String[]args){
final int number=100;
System.out.println("write n:");
int n;
do{

n = Input.readInt();


}while(n*n<= number);


System.out.println(n);

}
}
// I want 11 not 12 or 13 ....I changed the program many times but every time the out put is not that "n" which I want.
Thanks
Peter
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

Re: java programming

 
0
  #4
Sep 25th, 2004
Hi!
please help me whit this question.
Thanks
Peter
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 54
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: java programming

 
0
  #5
Sep 25th, 2004
I dont understand your question ... why dont you want to print 12 and you want to print 11 ??? both are greater than 100.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

Re: java programming

 
0
  #6
Sep 25th, 2004
Hi again!


Yes,both (11,and 12,13) are greater than 100. But the question is that the program must print out the first greater n, not the second or third greater n.
Again:
we have a nbr "nbr=3000"
we have n=54 //from keyboard
n=55 //from keyboard
n=56 //from keyboard

when we multiply n we get:
54x54=2916
55x55=3025
56x56=3136
the program must print 55 because it is the first greater n, we don not need that the program prints out the second greater n(56).
Regards
peter
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 54
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: java programming

 
0
  #7
Sep 25th, 2004
okay I give you a raw idea about your program ... if still you cant understand ... post again...
input n1 from keyboard
check if its square is greater than nbr
if yes put flag1 = n1
if no put flag1 = 0

input n2 from keyboard
check if its square is greater than nbr
if yes put flag2 = n2
if no put flag2 = 0

input n3 from keyboard
check if its square is greater than nbr
if yes put flag3 = n3
if no put flag3 = 0

compare flag1, flag2 and flag3 for the highest number
eliminate the highest
compare the other two left for the highest number
eliminate the highest

the last number left is what should be printed.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

Re: java programming

 
0
  #8
Sep 25th, 2004
Hi!
Yes yuor solution is OK, but if we have nbr=100;
and in the sametime our input are
13, 14, 15, or 50,70,91.....and if we compare these(n) we can not
find 11. the smallest one is not 11.
I mean if we have a nbr=12548796821
how many times we test each n.
Ex: the nbr 100 is between (10x10) and (11x11)
and we take the greater one.
thanks
Peter
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 54
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: java programming

 
0
  #9
Sep 26th, 2004
owww ! I misunderstood you ... okay let me try n then I'll post the solution for you
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC