convert the pseudocode comments into java code. public class Section_2_FillInThe
ID: 3784160 • Letter: C
Question
convert the pseudocode comments into java code.
public class Section_2_FillInTheCode
{
public static void main(String[] args)
{
int a = 10;
int b = 5;
double c;
// Convert the following sentences to legal Java instructions
// For each one print the values of variables and the result of the operation
// #1 b gets a plus 3 minus 7
// #2 b gets a times 4
// #3 a is incremented by 1 using a shortcut operator
// #4 a gets b times the sum of a plus 5
// #5 b gets the quotient of the division of a by 2
// #6 b gets the remainder of the division of a by 3
// #7 c gets the average of a and b
// #8 c is decremented by 1 using a shortcut operator
// #9 b is incremented by 5 using a shortcut operator
}
}
Explanation / Answer
Please put below code into file code.java
public class code
{
public static void main(String[] args)
{
int a = 10;
int b = 5;
double c;
System.out.println("a = " + a);
System.out.println("b = " + b);
// Convert the following sentences to legal Java instructions
// For each one print the values of variables and the result of the operation
// #1 b gets a plus 3 minus 7
System.out.println("#1 b gets a plus 3 minus 7");
b = a + 3 - 7;
System.out.println("b = " + b);
// #2 b gets a times 4
System.out.println("#2 b gets a times 4");
b = a*4;
System.out.println("b = " + b);
// #3 a is incremented by 1 using a shortcut operator
System.out.println("#3 a is incremented by 1 using a shortcut operator");
a++;
System.out.println("a = " + a);
// #4 a gets b times the sum of a plus 5
System.out.println("#4 a gets b times the sum of a plus 5");
a = b*(a+5);
System.out.println("a = " + a);
// #5 b gets the quotient of the division of a by 2
System.out.println("#5 b gets the quotient of the division of a by 2");
b = a/2;
System.out.println("b = " + b);
// #6 b gets the remainder of the division of a by 3
System.out.println("#6 b gets the remainder of the division of a by 3");
b = a%3;
System.out.println("b = " + b);
// #7 c gets the average of a and b
System.out.println("#7 c gets the average of a and b");
c = (a+b)/2;
System.out.println("c = " + c);
// #8 c is decremented by 1 using a shortcut operator
System.out.println("#8 c is decremented by 1 using a shortcut operator");
c--;
System.out.println("c = " + c);
// #9 b is incremented by 5 using a shortcut operator
System.out.println("#9 b is incremented by 5 using a shortcut operator");
b++;b++;b++;b++;b++;
System.out.println("b = " + b);
}
}
Sample Output:
a = 10
b = 5
#1 b gets a plus 3 minus 7
b = 6
#2 b gets a times 4
b = 40
#3 a is incremented by 1 using a shortcut operator
a = 11
#4 a gets b times the sum of a plus 5
a = 640
#5 b gets the quotient of the division of a by 2
b = 320
#6 b gets the remainder of the division of a by 3
b = 1
#7 c gets the average of a and b
c = 320.0
#8 c is decremented by 1 using a shortcut operator
c = 319.0
#9 b is incremented by 5 using a shortcut operator
b = 6
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.