Line 5 is missing a starting ". Line 6 is missing a ending ;. Line 7 has Name when it should be name. Remember that variable names start with a lowercase letter.
public class Test1
{
public static void main(String[] args)
{
String name = "Mary";
String color = "blue";
System.out.println(name + "'s favorite color is " + color);
}
}
Line 5 is missing a =. Line 6 is missing the closing ". Line 7 has Name when it should be name. Remember that a variable name starts with a lowercase letter. Line 8 is missing an ending +.
public class Test1
{
public static void main(String[] args)
{
String name = "Gabby";
String sport = "soccer";
System.out.println(name +
"'s favorite sport is " + sport);
}
}
The following code should print Your name is Carly and your favorite
color is red. Finish the code so that it prints the output correctly using the variables provided.
public class Test1
{
public static void main(String[] args)
{
String name = "Carly";
String color = "red";
System.out.println(
"Your name is "
+ name
+ " and your favorite color is "
+ color);
}
}
public class Test1
{
public static void main(String[] args)
{
String name = "Justin";
int age = 16;
System.out.println("Your name is " + name +
" and your age is " + age);
}
}
public class Test1
{
public static void main(String[] args)
{
String name = "Julian";
String color = "green";
String food = "pizza";
System.out.println(
name
+ "'s favorite color is "
+ color
+ ". His favorite food is "
+ food
+ ".");
}
}
public class Test1
{
public static void main(String[] args)
{
String movie = "The Princess Bride";
String book = "Harry Potter";
System.out.println("My favorite movie is " + movie + ". " +
"My favorite book is " + book + ".");
}
}
The following code should calculate the cost of a trip that is 300 miles if gas is $2.50 a gallon and your car gets 30 miles per gallon. However, the code has syntax errors, like missing semicolons, wrong case on names, or unmatched " or (. Fix the code so that it compiles and runs correctly.
Line 5 is missing a semicolon. Line 6 has Double instead of double. Remember that the primitive types all start with a lowercase letter. Line 8 has tripmiles instead of tripMiles. Remember that you should uppercase the first letter of each new word to make the variable name easier to read (use camel case).
The following code should calculate the body mass index (BMI) for someone who is 5 feet tall and weighs 110 pounds. However, the code has syntax errors, like missing semicolons, wrong case on names, or unmatched " or (. Fix the code so that it compiles and runs correctly.
Line 5 has Height instead of height. Remember that variable names should start with a lowercase letter. Line 6 is missing an equal sign. Line 7 is missing a * to square the height. Line 8 is missing a semicolon at the end of the statement.
The following code should calculate the number of miles that you can drive when you have $8.00 and the price of gas is 2.35 and the car gets 40 miles per gallon. However, the code has errors. Fix the code so that it compiles and runs correctly.
The following code should calculate the cost of an item that is on clearance (70% off) when you also have a coupon for an additional 20% off the clearance price. However, the code has errors. Fix the code so that it compiles and runs correctly.
The following code should calculate the number of whole days in 320893 seconds. However, the code has errors. Fix the code so that it compiles and runs correctly.
public class Test1
{
public static void main(String[] args)
{
int numSecs = 320893;
int numHours = numSecs / 3600;
int numDays = numHours / 24;
System.out.println(numDays);
}
}
Write the code to calculate the number of miles you can drive if you have a 10 gallon gas tank and are down to a quarter of a tank of gas and your car gets 32 miles per gallon.
Write the code to calculate the number of seconds in 3 days. Remember that there are 60 seconds in a minute and 60 minutes in an hour and 24 hours in a day.
public class Test1
{
public static void main(String[] args)
{
int secondsInMinute = 60;
int minutesInHour = 60;
int hoursInDay = 24;
int secondsInDay = secondsInMinute * minutesInHour * hoursInDay;
int secondsInThreeDays = secondsInDay * 3;
System.out.println(secondsInThreeDays);
}
}
Write the code to print the number of chicken wings you can buy if you have $4.50 and they cost $0.75 each. Remember that you can’t buy part of a wing.