Q2 and Q5 ask for the output of certain statements.Q3 and Q4 ask for full progra
ID: 3588600 • Letter: Q
Question
Q2 and Q5 ask for the output of certain statements.Q3 and Q4 ask for full programs, which I recommend you write in IntelliJ, to make sure they run correctly. Then copy-paste the code from IntelliJ to the txt or word file with the rest of your answers.You will need to download IntelliJ Community Edition as well as JDK (Java Development Kit). When you are creating a new project with IntelliJ, click "Download JDK" and follow the instructions. I need it in word file oo Turkcell 20:24 1. Write Java statements that accomplish each of the following tasks a) Display the message "Enter an integer:, leaving the cursor on the same line. b) Assign the product of variables b and c to variable a. c) Use a comment to state that a program performs a sample payroll calculation 2. Assuming that x 2 and y-3, what does cach of the following statements display? d) System.out.print fTx-%dKa-.x); e) System.out.printfi.Value of %d + %d is %d%a". x, x, (x + xt f) System.out.printfrx="k g) System.out.printd-9dn,x+y).(y x)) 3. Write an application that displays the numbers I to 4 on the same line, with cach pair of adjacent numbers separated by one space. Use the following techniques: h) Use the Systemout println statement i) Use the System.out.print statement. ) Use the System.out.printf statement. 4. Write an application that asks the user to enter two integers, obtains them from the user and prints the square of each, the sum of their squares, and the difference of the squares (first mumber squared minus the second number squared) and multiplication and division of them. 5. What does the following code print? System out printf in nnnExplanation / Answer
1. a. System.out.print("Enter an integer: ");
1. b, a = b * c;
1. c.
/**
* Payroll Calculation
*
* <p> This class calculates the payroll of the employees for a selected month.
*
* @author
* @version 1.0
* @see also Employee, Department
*/
2. d. x=2
2. e. Value of 2 + 2 is 4
2. f. x=
2. g. 5 - 5
3. h.
public class PrintLnExample {
public static void main(String args[]) {
int x=1;
System.out.println(x + " " + (++x) + " " + (++x) + " " + (++x));
}
}
3. i.
public class PrintExample {
public static void main(String args[]) {
for (int i=1; i<=4; i++) {
System.out.print(i);
if (i<4) {
System.out.print(" ");
}
}
}
}
3. j.
public class PrintFExample {
public static void main(String args[]) {
for (int i=1; i<=4; i++) {
System.out.printf("%d",i);
if (i<4) {
System.out.printf(" ");
}
}
}
}
4.
import java.util.Scanner;
public class PrintFExample {
public static void main(String args[]) {
// read the input
Scanner sc = new Scanner(System.in);
System.out.println("Enter two integers");
int x = sc.nextInt();
int y = sc.nextInt();
int x2 = x*x;
int y2 = y*y;
System.out.println("Square of first integer is " + x2);
System.out.println("Square of second integer is " + y2);
System.out.println("Sum of the squares of both integers are " + (x2+y2));
System.out.println("Difference of the squares of both integers (first number squared minus the second number squared) are " + (x2-y2));
System.out.println("Multiplication of the squares of both integers are " + (x2*y2));
System.out.println("Division of the squares of both integers are " + (x2/y2)); // Note: if second number is 0, this will throw Division by Zero error
}
}
5.
*
**
***
****
*****
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.