Assignment1 - / The "Assignment1" class. import apsc142.*;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// The "Assignment1" class. import apsc142.*; public class Assignment1 { public static void main (String[] args) { //question 3 / int answer3A, answer3B; double answer3C; answer3A= 5 + 10 % 3 + 2; //The original expression is legal in Java. //Answer is 14 (correct). Considering that desired % to mean modulus (the remainder). //Remember % takes precedence over +. answer3B= 5 + 10 %(3+2); //The original expression is legal in Java. //Answer is 5 (correct). Considering that desired % to mean modulus (the remainder). //Remember () takes precedence over everything. answer3C= 23 /(4.0/8.0); //The original expression is illegal in Java. /*The original problem in 23/(4/8) was that Java considered 4/8 an interger and trunkated 0.5 to 0. We can't divide by 0, and this is what cause the error. We had to change the decleration of Answer3A from an int to a double as well as type 4.0 and 8.0 insteat of 4 and 8. This shows Java that we are using doubles.*/ //Answer should be 46.0. / System.out.println ("Question 3");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/01/2010 for the course APPLIED SC 142 taught by Professor Professorstansimmons during the Winter '10 term at Queens University.

Page1 / 2

Assignment1 - / The "Assignment1" class. import apsc142.*;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online