double
allows. Make sure to test your
program carefully and convince yourselves that the there is no
precision loss (Hint: diameter = 1 is a good test case). You may not
change the type of the variable diameter, but you may change its
value to test the program.
// Written by Elena Machkasova 9/5/04
// Modified by
public class Precision {
public static void main(String[] args) {
int diameter = 1; // change values to test
final double PI = 3.141592654; // a constant (usually named in CAPS)
int circumference = diameter * (int) PI;
double radius = diameter / 2;
double area = PI * radius * radius;
System.out.println("If the diameter of a circle is " + diameter);
System.out.println("then the circumference is " + circumference);
System.out.println("and the area is " + area);
}
}
double
:
fahrenheit
and celsius
. Initialize
fahrenheit
to some value. Then the program must perform
the following operations:
To test the program, create a new queue, insert some elements into it, then reverse it using a stack, and then print out the elements in the resulting queue. You don't need to put the elements back into the queue after you have printed them out.
Make sure that you have tested your program for different queue sizes, including an empty queue.
while
loop to
accomplish this task. Important: at the end the stack should be
returned to the original state (i.e. no elements should be removed and
the order of the elements should not change).
String s1 = "(aaa(bc)[6{nn}])";
is a string with matching brackets, while the string
String s1 = "{[1](2[3)]}";
is not. Below is an example of a loop that goes through the entire
string character by character:
String s1 = "(aaa(bc)[6{nn}])";
int i = 0;
while(i < s1.length()) {
char c = s1.charAt(i);
i = i + 1; // to get the next character
// the rest of your code goes below:
}
Another helpful tip is on how to exit a program: if you have
discovered that backets don't match, you should print a message and
exit. To exit a program, use
System.exit(0);
. Make sure to test your program extensively. Keep your test cases in comments so that I can check how you tested the program. Important: the program must print the answer for any given string, it should never produce a run-time error. If any of the test cases don't work, please write a note in comments explaining what didn't work and, optionally, why you think this is happening. Understanding the cause of an error helps your grade.