1. Lunch Money This is not a complete program just the JAVA statements needed Yo
ID: 3870795 • Letter: 1
Question
1. Lunch Money This is not a complete program just the JAVA statements needed
You may check your answers in Eclipse.
Write Java statements that will declare and initialize a variable to represent the money that you have for lunch today. You have 5 dollars and 72 cents in your wallet.
You spend $3.33 for lunch
Write a single Java statement that will print out the following (except use your own name) including how much is left:
“My name is Your Name and I have $5.72 for lunch today and I have left “
Explanation / Answer
Firstly Write Your own Name in place of your name
My name is Your Name and I have $5.72 for lunch today and I have left “
//This is code to check
public class MyClass {
public static void main(String args[]) {
double x = 5.72;
double y = 3.33;
double z = x-y;
System.out.println( "My name is Your Name and I have $"+ x + " for lunch today and I have left $" + z);
}
}
// declaration
double x = 5.72;
double y = 3.33;
double z = x-y;
// single statement
System.out.println( "My name is Your Name and I have $"+ x + " for lunch today and I have left $" + z);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.