Please remember that homework must be handed in on time. No late homework will be accepted.
Be sure to read through Chapter 2 of your textbook for more information about Java variables, data types, operators and statements.
double speed = timeInHours / distanceInMiles; String title = 'Angels and Demons'; int x = 110/2.5; int trillion = 1000000 * 1000000;
6 + 5 * 4 - 3 / 2 (int)(60.0 / 9) (double)(72 % 5)
System.out.println(2 + 2 + " = 4");
System.out.println("4 = " + 2 + 2);
System.out.println("4 = " + (2 + 2));
int a = 2;
System.out.println(a);
a += 3;
System.out.println(a);
a *= 4;
System.out.println(a);
a -= 5;
System.out.println(a);
a /= 6;
System.out.println(a);
a++;
System.out.println(a);
int x = 4;
int y = 10;
double a = 10.0;
double b = 4.0;
System.out.println((double)(x / y));
System.out.println((double) x / y);
System.out.println((int)(a / b));
System.out.println((int) a / b);
public class GasolinePaymentComputer
{
public static void main(String[] args)
{
double pricePerGallon = 2.239; // $2.239 per gallon
int numGallonsPurchased = 50;
System.out.println("Total gas purchase = $" +
pricePerGallon * numGallonsPurchased);
}
}
Running this program produces the following output:
Total gas purchase = $111.94999999999999
Explain why the output does not show $111.95 as the expected answer.
public class StampComputer
{
public static void main(String[] args)
{
// In this example, the user has $20.09 to buy stamps
int numDollars = 20;
int numCents = 9;
int stampCost = 44; // each stamp costs 44 cents
// Compute the maximum number of stamps the user can purchase
int numStamps = ____________________________________________________;
// Compute the amount of change (in cents) the user will have left over
int change = ____________________________________________________;
System.out.println("You can purchase " + numStamps + " stamps.");
System.out.println("You will have " + change + " cents remaining.");
}
}
For example, the output of this method for the data given should be
You can purchase 45 stamps. You will have 29 cents remaining.