Professional Documents
Culture Documents
import java.util.*;
import java.io.*;
int units;
double rent;
double startRent;
double rentInc;
double maintenance;
double totalMaintenance;
double earnings;
double earnings2;
earnings2 = (units-1)*(rent+rentInc)-maintenance*(units-1);
earnings = units*rent-maintenance*units;
do
{
units--;
rent = rent+rentInc;
earnings = (units--)*(rent+rentInc)-(maintenance*(units--));
}
while (earnings > earnings2);
}
}
Write a program that prompts the user to input a positive ineteger. It should then
output a message indicating whether the number is prime number. Note: 2 is the
only even number that is prime. An odd integer is prime if it is not divisible by an
odd integer less than or equal to the square root of the number.
import java.util.*;
if (num < 1)
else if (num == 2)
System.out.print("its a prime yey!");
else if (num % 2 == 0)
System.out.print("its not a prime ");
}
}
Write a program that accepts as input the mass (in grams) -8
and density
and outputs the volume of ,)in grams per cubic centimeters(
the object using
the formula: density = mass / volume. Format your output to
two decimal
.places
arrow_forward
Question
Asked Apr 21, 2020
79 views
Write a program that accepts as input the mass, in grams, and density, in
grams per cubic centimeters, and outputs the volume of the object using the
formula: volume 5 mass / density. Format your output to two decimal
places.
check_circle
Expert Answer
Step 1
the below given Java program will obey the following rubrics:
Step 2
Program code:
import java.text.DecimalFormat;
import java.util.Scanner;
//class volume
public class Volume
//main method
public static void main(String[] args)
{
double mass = 0;
double density = 0;
do {
if(mass < 0)
{
}
do {
...
This program reads the user's first name and last name,
* separated by a space. It then prints the user's first and
* last names separately, along with the number of characters
* in each name. It also prints the user's initials. Note that
* this program will crash if the user's input does not contain
* a space.
*/
public class FirstNameLastName {