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

Recommended Answers

All 8 Replies

what exactly are you trying to do ... you can use simple if statements to check whether nbr is greater than zero or not.

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)

Code

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

Hi!
please help me whit this question.
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.

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

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.

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

owww ! I misunderstood you ... okay let me try n then I'll post the solution for you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.