public class Variables_Input {
public static void main(String[] args) {
int myAge = 25;
double myShoeSize = 42.5;
String myName = "Jack";
System.out.println("My name is " + myName);
System.out.println("My shoe size is " + myShoeSize);
System.out.println("I am " + myAge + " years old");
}
}
Close
public class Variables_Input {
public static void main(String[] args) {
double myHeight = 1.8;
char initial = 'J';
boolean isStudent = true;
System.out.println("My height is " + myHeight);
System.out.println("My initial is " + initial);
System.out.println("Am I a student? " + isStudent);
}
}
Close
public class Variables_Input {
public static void main(String[] args) {
int number1 = 8;
int number2 = 5;
double sum = number1 + number2;
double product = number1 * number2;
System.out.println("The sum of " + number1 + " and " + number2 + " is " + sum);
System.out.println("The product of " + number1 + " and " + number2 + " is " + product);
}
}
Close
The sum of 12 and 7 is 19.0
The difference when 7 is subtracted from 12 is 5.0
The product of 12 and 7 is 84.0
The quotient when 12 is divided by 7 is approximately 1.0
Close
public class Variables_Input {
public static void main(String[] args) {
int numberA = 12;
int numberB = 7;
double sum = numberA + numberB;
double difference = numberA - numberB;
double product = numberA * numberB;
double quotient = numberA / numberB;
System.out.println("The sum of " + numberA + " and " + numberB + " is " + sum);
System.out.println("The difference when " + numberA + " is subtracted from " + numberB + " is " + difference);
System.out.println("The product of " + numberA + " and " + numberB + " is " + product);
System.out.println("The quotient when " + numberA + " is divided by " + numberB + " is approximately " + quotient);
}
}
Close
import java.util.Scanner;
public class UserIntroduction {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Enter your age: ");
int age = scanner.nextInt();
System.out.println("Hi! My name is " + name + " and I am " + age + " years old!");
scanner.close();
}
}
Close
Assuming the given values were "Jack" and 25:
Hi! My name is Jack and I am 25 years old!
I was born in 1999
Close
import java.util.Scanner;
public class Variables_Input {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Enter your age: ");
int age = scanner.nextInt();
int birthYear = 2024 - age;
System.out.println("Hi! My name is " + name + " and I am " + age + " years old!");
System.out.println("I was born in " + birthYear);
}
}
Close
Assuming the given values are "Jack" and 5000.
Hi! My name is Jack and my monthly salary is $5000.
Your monthly bonus is $400.0, making your total monthly earnings $5400.0.
Your annual earnings including the bonus are $64800.0.
Close
import java.util.Scanner;
public class Variables_Input {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Enter your monthly salary: ");
double salary = scanner.nextDouble();
double bonus = salary * 0.08;
double totalMonthlyEarnings = salary + bonus;
double annualEarnings = totalMonthlyEarnings * 12;
System.out.println("Hi! My name is " + name + " and my monthly salary is $" + salary);
System.out.println("Your monthly bonus is $" + bonus + " ,making your total monthly earnings $" + totalMonthlyEarnings);
System.out.println("Your annual earnings including the bonus are $" + annualEarnings);
}
}
Close
Assuming the given values are "Alice", 4000, and 35.
Hi! My name is Alice, my monthly salary is $4000.0, and I work 35 hours per week.
Your hourly rate is $31.43, and your monthly bonus is $400.0, making your total monthly earnings $4400.0.
Your annual earnings including the bonus are $52800.0.
Close
import java.util.Scanner;
public class Variables_Input {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Enter your monthly salary: ");
double salary = scanner.nextDouble();
System.out.print("Enter your hours worked per week: ");
int hoursWorked = scanner.nextInt();
double bonus = salary * 0.1;
double totalMonthlyEarnings = salary + bonus;
int hoursWorkedMonth = hoursWorked * 4;
double hourlyRate = totalMonthlyEarnings / hoursWorkedMonth;
double annualEarnings = totalMonthlyEarnings * 12;
System.out.println("Hi! My name is " + name + " , my monthly salary is $" + salary + " and I work " + hoursWorked + " per week.");
System.out.println("Your hourly rate is $" + hourlyRate + " , and your monthly bonus is $" + bonus + " making your total monthly earnings $" + totalMonthlyEarnings);
System.out.println("Your annual earnings including the bonus are $" + annualEarnings);
}
}
Close