| | |
java programming
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
what exactly are you trying to do ... you can use simple if statements to check whether nbr is greater than zero or not.
•
•
Join Date: Sep 2004
Posts: 24
Reputation:
Solved Threads: 0
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
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
I dont understand your question ... why dont you want to print 12 and you want to print 11 ??? both are greater than 100.
•
•
Join Date: Sep 2004
Posts: 24
Reputation:
Solved Threads: 0
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
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
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.
•
•
Join Date: Sep 2004
Posts: 24
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Please rate my Java programming forums (Website Reviews)
- Java Programming Classes (Java)
- Java Programming Help!!!!!!!!!!!!!!!!! (Java)
- Java as a programming platform. (Java)
- Java Programming (Java)
- java programming language (Java)
Other Threads in the Java Forum
- Previous Thread: zip file extraction
- Next Thread: Working with JLayeredPane and positioning of components.. HELP!
| Thread Tools | Search this Thread |
6 actuate android api applet application array arrays automation balls binary bluetooth bold business c++ chat class classes client code codesnippet collections component coordinates database defaultmethod doctype dragging ebook eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list loop looping map method methods mobile mysql netbeans newbie nextline parameter php print problem program programming project recursion recursive scanner screen sell server set size sms sort sql string sun swing swt threads tree user websites windows






