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

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• May 3rd, 2012, 09:06 AM
thecraetiveman
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.

• May 3rd, 2012, 10:13 AM
Norm
Re: How i can solve this question? help me please ...
Do you have any specific java programming questions?
What problems are you having?
• May 3rd, 2012, 10:19 AM
thecraetiveman
Re: How i can solve this question? help me please ...
i do not know who i can solve this question can you help me?
• May 3rd, 2012, 10:28 AM
Norm
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?
• May 3rd, 2012, 10:41 AM
thecraetiveman
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?
• May 3rd, 2012, 10:46 AM
Norm
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.
• May 3rd, 2012, 10:51 AM
thecraetiveman
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 ?
• May 3rd, 2012, 10:57 AM
Norm
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.
• May 4th, 2012, 01:05 AM
thecraetiveman
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);
}
}
}
• May 4th, 2012, 05:46 AM
Norm
Re: How i can solve this question? help me please ...
Quote:

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.
• May 4th, 2012, 01:38 PM
thecraetiveman
Re: How i can solve this question? help me please ...
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 ?
• May 4th, 2012, 01:42 PM
Norm
Re: How i can solve this question? help me please ...
Quote:

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
• May 4th, 2012, 01:50 PM
thecraetiveman
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);
}
}
}
• May 4th, 2012, 01:51 PM
Norm
Re: How i can solve this question? help me please ...
Where do you test the value that the user entered?
• May 4th, 2012, 01:55 PM
thecraetiveman
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);
• May 4th, 2012, 01:58 PM
Norm
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
• May 4th, 2012, 01:59 PM
thecraetiveman
Re: How i can solve this question? help me please ...
i dont know can you help me ?
where is my mistake exactly?
• May 4th, 2012, 02:05 PM
Norm
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?
• May 4th, 2012, 02:07 PM
thecraetiveman
Re: How i can solve this question? help me please ...
sorry i am not have any idea ?
can you explain more?
• May 4th, 2012, 02:12 PM
Norm
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,
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.
• May 4th, 2012, 02:37 PM
thecraetiveman
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 ?>
• May 4th, 2012, 02:42 PM
Norm
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;
• May 4th, 2012, 02:47 PM
thecraetiveman
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
• May 4th, 2012, 02:52 PM
Norm
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?
• May 4th, 2012, 02:54 PM
thecraetiveman
Re: How i can solve this question? help me please ...