- /**Practice Test Chap 5 & 6,
Data Types, Variables, and Arithmetic
- * @author T. K. Rogers
@version 10-4-05 */
-
- public class
IntMath {
-
- public static void
main ( ) {
-
int
intAnswer,
-
a = 2,
-
b = 3,
-
c = 4;
-
double doubleAnswer,
-
x = 4,
-
y = 6,
-
z = 8;
- /* 1*/ intAnswer = (a + b) % b / c
* (2 * a) / c + 8 ;
-
System.out.println ("1) " + intAnswer) ;
- /* 2*/ intAnswer = (a + (b % b))
/ ((c * (2 * a)) / c) + 7 ;
-
System.out.println ("2) " + intAnswer) ;
- /* 3*/ intAnswer = 1 - ((a + b) %
b / c) * (2 * (a / c));
-
System.out.println ("3) " + intAnswer);
- /* 4*/ intAnswer = (int) y % b + (int) (x
/ z * b)/ (int)z;
-
System.out.println ("4) " + intAnswer);
- /* 5*/ intAnswer = (b / c)* (4 *
(a + (b + c)) / c) + 5;
-
System.out.println ("5) " + intAnswer);
- /* 6*/ doubleAnswer = z * (b / c)
+ a;
-
System.out.println ("6) " + doubleAnswer);
- /* 7*/ doubleAnswer = y % b + (int)(x
/ z * b)/(int)(z * z)/9 + 3;
-
System.out.println ("7) " + doubleAnswer);
- /* 8*/ doubleAnswer = 1-(y %
b + (int)(x / z * b)/(int)(z * z));
-
System.out.println ("8) " + doubleAnswer);
- /* 9*/ doubleAnswer = 3 + (a /12)
* b * (z* x * y + 2 * z)/ z * 17.0 ;
-
System.out.println ("9) " + doubleAnswer);
- /*10*/ doubleAnswer = 12 * (b/a) * z* (double)(a/c);
-
System.out.println ("10) " + doubleAnswer);
- }
- } /*
- 11) Write the output for
the above program.
- 12) Write a software
on-off switch which turns off (changes from one to zero) at an
-
integer value of 5
- 13) Write a short
program which uses command line input to input an integer value
-
and test to see if it is evenly divisible by 17. The program will outputs a 1
if
-
evenly divisible and a 0 if not.
- 14) Write a short code
segment which takes a double called dollars that
-
represents money and rounds tenths of cents up.
*/
// Have you tried and tried yet still can't figure number 13 ?
Click here.