- /**
- * Practice problems for
integer math, order of operation, and type casting.
- *
- * @author TK Rogers
- * @version 11-08-10
- */
- public class
IntPractice {
-
public static void main ( ) {
-
int intAnswer,
-
a = 1,
-
b = 2,
-
c = 3;
-
double doubleAnswer,
-
x = 4,
-
y = 5,
-
z = 6;
-
intAnswer = ( a * b % b / c * 2 ) * a / c ;
-
System.out.println ( "1) " + intAnswer ) ;
- // 1) _________
-
-
intAnswer = (a + ( b % b )) / (( c * 2 * a ) / c) ;
-
System.out.println ( "2) " + intAnswer ) ;
- // 2) _________
-
-
intAnswer = (int) ((( a + b ) % 2.0 * b / c ) *
(2 * (1.0 * a / c))) ;
-
System.out.println ( "3) " + intAnswer ) ;
- // 3) _________
-
-
intAnswer = (int) y % b / 2 + (int)
( x / z * b ) ;
-
System.out.println ( "4) " + intAnswer ) ;
- // 4) _________
-
-
intAnswer = ( b / c )* ( 2* ( a + ( b + c )) / c) ;
-
System.out.println ( "5) " + intAnswer ) ;
- // 5) _________
-
doubleAnswer = z * b / c ;
-
System.out.println ( "6) " + doubleAnswer ) ;
- // 6) _________
-
-
doubleAnswer = y % b + (int) ( x / z * b ) / (int)
( z * z ) ;
-
System.out.println ( "7) " + doubleAnswer ) ;
- // 7) _________
-
-
doubleAnswer = (int) ( y % b + ( x / z * b ) / (
z * z )) + 'b';
-
System.out.println ( "8) " + doubleAnswer );
- // 8) _________
-
-
doubleAnswer = 'a' * b * ( z* x * y + 2 * z ) / z * ( a / 2 ) ;
-
System.out.println ("9) " +doubleAnswer);
- // 9) _________
-
-
doubleAnswer = b * z* (double) ( a/c ) + 'z' ;
-
System.out.println ( "10) " + doubleAnswer ) ;
- //10) _________
- }
- }