Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 50 of 50

Thread: How i can solve this question? help me please ...

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    Add code to test if r is negative and exit the program is it is.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    mport java.util.Scanner;


    public class a{
    public static void main(String[] args){
    for (double i = 0; i <9; i++) {
    if (r < o)
    System.out.println("r is negative");
    else
    System.out.println("positive");
    Scanner scan=new Scanner(System.in);

    double a,r,p;

    System.out.println("Enter value of radius:");
    r=scan.nextDouble();

    a=3.14*r*r ;
    p=2*3.14*r;

    System.out.println("Area= "+a);
    System.out.println("Perimeter = "+p);
    }
    }
    }








    ?? where is my mistake >?

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    You need to understand that the statements in the program are executed in the same order as they are entered in the source. The first state is executed first, then the next one and then the next one.

    At what statement in the source code is the r variable given a value typed in by the user? You can not test it for a negative value beFore the value has been entered. You must test its value after the value has been read in.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    ok where i have to but the if statement and why it is not working with my?

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    Did you understand what I wrote about the order that statements in a program are executed?

    What will be the value of r when your if statement testing its value is executed?

    What happens when you execute the program now? Copy the console and paste it here.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    import java.util.Scanner;


    public class a{
    public static void main(String[] args){
    for (double i = 0; i <9; i++) {

    Scanner scan=new Scanner(System.in);

    double a,r,p;

    System.out.println("Enter value of radius:");
    r=scan.nextDouble();

    a=3.14*r*r ;
    p=2*3.14*r;

    System.out.println("Area= "+a);
    System.out.println("Perimeter = "+p);
    if ( r < o)
    System.out.println("r is negative");
    else
    System.out.println("positive");
    }
    }
    }


    am using Dr java .. i understand what you say but am confusing

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    What does the console look like when you execute the program? Please copy and paste it here.

    Can you explain what the problem is with the way the program is executing?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    1 error found:
    File: C:\Users\Quick age\Desktop\a.java [line: 21]
    Error: C:\Users\Quick age\Desktop\a.java:21: cannot find symbol
    symbol : variable o
    location: class a


    the console :
    nothing appear because of the problem which is in the code

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    Define the variable o in class a so it can be used on line 21.

    What code is on line 21?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    if ( r < o)
    System.out.println("r is negative");
    else
    System.out.println("positive");

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    Why are you comparing the value of the variable r to the variable: o?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #37
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    because if it is less than zero it will equal negative
    can you help me to done this step if you allow ?
    i have to done the program

  13. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    Check your keyboard. A zero(0) is different from the letter(o)
    If you don't understand my answer, don't ignore it, ask a question.

  14. #39
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    thanks my frend but how i can stop the program when i unter negative number ?>

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    See post #12
    If you don't understand my answer, don't ignore it, ask a question.

  16. #41
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    where i have to put System.exit(0);?

  17. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    Put it at the place in the code where you want the program to stop executing.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #43
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    it is not working

    import java.util.Scanner;


    public class a{
    public static void main(String[] args){
    for (double i = 0; i <9; i++) {

    Scanner scan=new Scanner(System.in);

    double a,r,p;

    System.out.println("Enter value of radius:");
    r=scan.nextDouble();

    a=3.14*r*r ;
    p=2*3.14*r;

    System.out.println("Area= "+a);
    System.out.println("Perimeter = "+p);
    if ( r < 0)

    System.out.println("r is negative");
    System.exit(0);

    else
    System.out.println("positive");

    }
    }
    }

  19. #44
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    4 errors found:
    File: C:\Users\Quick age\Desktop\a.java [line: 26]
    Error: C:\Users\Quick age\Desktop\a.java:26: 'else' without 'if'
    File: C:\Users\Quick age\Desktop\a.java [line: 27]
    Error: C:\Users\Quick age\Desktop\a.java:27: <identifier> expected
    File: C:\Users\Quick age\Desktop\a.java [line: 27]
    Error: C:\Users\Quick age\Desktop\a.java:27: illegal start of type
    File: C:\Users\Quick age\Desktop\a.java [line: 30]
    Error: C:\Users\Quick age\Desktop\a.java:30: class, interface, or enum expected

  20. #45
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    You should always enclose code in if statements and loops in {}. Your code has left off the {} to enclose the code in the if statement.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #46
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    is it ok now ?

    import java.util.Scanner;


    public class a{
    public static void main(String[] args){
    for (double i = 0; i <9; i++) {

    Scanner scan=new Scanner(System.in);

    double a,r,p;

    System.out.println("Enter value of radius:");
    r=scan.nextDouble();

    a=3.14*r*r ;
    p=2*3.14*r;

    System.out.println("Area= "+a);
    System.out.println("Perimeter = "+p);
    if ( r < 0){

    System.out.println("r is negative");
    System.exit(0);
    }
    else
    System.out.println("positive");

    }
    }
    }

  22. #47
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: How i can solve this question? help me please ...

    Does it execute the way you want?

    One suggestion: Use the Math class's PI variable for a more accurate value for pi.
    If you don't understand my answer, don't ignore it, ask a question.

  23. The Following User Says Thank You to Norm For This Useful Post:

    thecraetiveman (May 4th, 2012)

  24. #48
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    thank you very math my friend ok i will do it
    it look show the result and close directly >>

  25. #49
    Junior Member
    Join Date
    May 2012
    Posts
    3
    My Mood
    Cool
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    Hi ,
    One more thing that u can do is to use while loop and check for r being negative while(r>0) if so get the input from user and print the values of are a nad perimeter.
    By the way ur area would come wrong.
    Regards,
    Devesh

  26. #50
    Junior Member
    Join Date
    May 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How i can solve this question? help me please ...

    thanks my dear i use your way and it successful thanks for you ...

Page 2 of 2 FirstFirst 12

Similar Threads

  1. please help solve this question
    By thatguy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 29th, 2012, 06:53 PM
  2. Please can anyone help solve this ?
    By jennyb in forum Java Theory & Questions
    Replies: 1
    Last Post: January 6th, 2012, 08:45 PM
  3. using while to solve this question !
    By deathpain in forum Java Theory & Questions
    Replies: 2
    Last Post: November 19th, 2011, 03:46 PM
  4. please solve this question on html:multibox?
    By tejz in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: February 13th, 2010, 02:18 AM
  5. Replies: 2
    Last Post: May 16th, 2009, 05:23 AM