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 1 of 2 12 LastLast
Results 1 to 25 of 50

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

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

    Wink How i can solve this question? help me please ...

    Write a Java program that will read the radius of a circle (radius in double) and compute the following using methods. The main program
    should repeat until the user enters a negative value for the radius of the circle.

    • Use a method to compute the area of circle using the formula
    Area=3.14*r where 3.14 is a constant
    • Use a method to computer the perimeter of the circle using the formula 2*3.14*r
    where 3.14 is a constant

    The program should use both method and display the two results for each radius that is input until a negative value for radius is input.


    help me please...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Do you have any specific java programming questions?
    What problems are you having?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    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 ...

    i do not know who i can solve this question can you help me?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Are you trying to learn how to write programs in java?
    What have you learned so far? Can you use an of what you have learned to start solving this problem?

    Post your current code and ask some questions about the part you are having problems with.
    Make a list of what the program must do to solve the problem. Then work on the items in the list one at a time.

    What is the first thing the program must do?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    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 ...

    i know how i can write a java program but i am not understand how i can solve this question
    i think i have to use scanner and loop an method but i am confusing because of the stress of the study .
    can you help me?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    One problem at a time.

    Look at how to use the Scanner class to read in a number from the user from (System.in).
    The nextInt method would be used there.

    When you get the code to work with one number being read in, then worry about using a loop to get more than one number.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    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, can you solve the question for me and i will understand it
    sorry for this request but i have a lot of home works and i have to done a research and i have midterm and quize can you help me ?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Sorry, we don't do student homework. If we did, we should get the credit for the work not you.
    If you have questions or problems, post them with the code you are having problems with.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following 2 Users Say Thank You to Norm For This Useful Post:

    copeg (May 3rd, 2012), deveshinjiit@gmail.com (May 6th, 2012)

  10. #9
    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 ...

    hi, sorry i answer late,
    i try to do the program but i have problem with the loop
    mport java.util.Scanner;


    public class a{
    public static void main(String[] args){

    Scanner scan=new Scanner(System.in);

    double a,r,p;
    for (double r=0; r<0; r++){

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

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


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

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    i have problem with the loop
    You need to look at how to code a for loop:
    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

    Look especially at the termination expression.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #11
    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 for your reply ,
    i see the link but i am still not able to solve this problem The program should use both method and display the two results for each radius that is input until a negative value for radius is input.



    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);
    }
    }
    }


    i dont know how i can stop the program when i input negative number ?

  13. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    i dont know how i can stop the program when i input negative number
    Use an if statement to test if the number that was input by the user is a negative number. If it is you can use the System.exit(0); statement to stop the program.

    What happens with your code if the user wants to enter 14 numbers before quiting?

    The Math class has a constant static variable with a more accurate value for pi: PI
    Last edited by Norm; May 4th, 2012 at 01:52 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #13
    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 ...

    i am still can not stop the program

    import java.util.Scanner;


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

    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);
    }
    }
    }

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Where do you test the value that the user entered?
    If you don't understand my answer, don't ignore it, ask a question.

  16. #15
    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 ...

    i use this but am still have a problem

    for (double i = 0; i < 9; i++) {
    if (i<0)
    System.out.println("print i");
    else
    System.exit(0);

  17. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Where does the user enter the input into the program? Where is it read into a variable?
    The variable i is the for loop control variable. i starts at 0 and increases to 9. It will never be less than 0
    If you don't understand my answer, don't ignore it, ask a question.

  18. #17
    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 ...

    i dont know can you help me ?
    where is my mistake exactly?

  19. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    The mistake is the code is looking at the loop control variable and not at the variable where the input is read from the user.

    Where does the code read input from the user?
    If you don't understand my answer, don't ignore it, ask a question.

  20. #19
    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 ...

    sorry i am not have any idea ?
    can you explain more?

  21. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Work on understanding what needs to be done to read input from a user.
    Write a small simple program that
    asks a user to enter a number,
    reads that number
    and prints out the number that the user entered.

    When you get that to work you will know how to read input from a user.
    and will be able to come back to this program and see where it is reading input from the user.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #21
    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 ty {
    public static void main(String[] args){
    Scanner input= new Scanner(System.in);
    System.out.println("Enter a number");
    int a=input.nextInt();
    int c=3;
    int b=3;
    a=b+c;
    System.out.println(a);

    }
    }

    but am still have problem ?>

  23. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    Can you explain what the problem is? The code in post#21 shows you can write code to get input from a user.
    Where in the code in post #13 do you get input from a user? What variable is the input read into? That is where you need to test for a negative value.

    BTW I said the small program should print out what the user entered. What do the variables: b & c have to do with the assignment? They are used to destroy the value of a: a = b+c;
    Last edited by Norm; May 4th, 2012 at 02:44 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #23
    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 ...

    please can you solve the problem for me i have to end it before i sleep i have to submit it tomorrow ? the time with me now 11:47 pm

  25. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

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

    I've been trying to tell you what variable to test. I've asked you to find it and test its value.
    The code inside the loop has these varibles: a,i,p,r
    Which one of those is what the user has entered into the program?
    If you don't understand my answer, don't ignore it, ask a question.

  26. #25
    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 ...

    r the radius

Page 1 of 2 12 LastLast

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, 09:45 PM
  3. using while to solve this question !
    By deathpain in forum Java Theory & Questions
    Replies: 2
    Last Post: November 19th, 2011, 04: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, 03:18 AM
  5. Replies: 2
    Last Post: May 16th, 2009, 05:23 AM