subject

ZyLab training: Interleaved input / output (Java) Auto-graded programming assignments have numerous advantages, but have some challenges too. Students commonly struggle with realizing that example input / output provided in an assignment's specification interleaves input and output, but the program should only output the output parts. If a program should double its input, an instructor might provide this example:
Enter x:
5
x doubled is: 25
Students often incorrectly create a program that outputs the 5. Instead, the program should only output the output parts:
Enter x:
x doubled is: 25
The instructor's example is showing both the output of the program, AND the user's input to that program, assuming the program is developed in an environment where a user is interacting with a program. But the program itself doesn't output the 5 (or the newline following the 5, which occurs when the user types 5 and presses enter).
Also, if the instructor configured the test cases to observe whitespace, then according to the above example, the program should output a newline after Enter x: (and possibly after the 25, if the instructor's test case expects that).
The program below incorrectly echoes the user's input to the output.
Try submitting it for grading (click "Submit mode", then "Submit for grading"). Notice that the test cases fail. The first test case's highlighting indicates that output 3 and newline were not expected. In the second test case, the -5 and newline were not expected.
Remove the code that echoes the user's input back to the output, and submit again. Now the test cases should all pass.
import java. util. Scanner;
public class DoubleNum {
public static void main(String[] args) {
Scanner scnr = new Scanner(System. in);
int x;
System. out. println("Enter x: ");
x = scnr. nextInt();
System. out. println(x); // Student mistakenly is echo'ing the input to output to match example
System. out. println("x doubled is: " + (2 * x));
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 01:10
Are special combinations of keys that tell a computer to perform a command. keypads multi-keys combinations shortcuts
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
Write a program that displays the following menu: geometry calculator 1. calculate the area of a circle 2. calculate the area of a rectangle 3. calculate the area of a triangle 4. quit enter your choice (1-4): if the user enters 1, the program should ask for the radius of the circle and then display its area. use the following formula: area = ď€(the square of r) use 3.14159 for ď€ and the radius of the circle for r. if the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. use the following formula: area = length * width if the user enters 3, the program should ask for the length of the triangle’s base and its height, and then display its area. use the following formula: area = base * height * .5 if the user enters 4, the program should end. input validation: display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height. note: if the user enters an improper menu choice (1-4), the program prints "the valid choices are 1 through 4. run the program again and select one of those." if the user enters a negative radius, the program prints "the radius can not be less than zero." if the user enters a negative value for height or base, the program prints "only enter positive values for base and height."
Answers: 1
question
Computers and Technology, 24.06.2019 22:00
True or false technology is often discovered by accident
Answers: 2
question
Computers and Technology, 25.06.2019 08:10
Spreadsheet software is more powerful than financial planning software. - true or false
Answers: 2
You know the right answer?
ZyLab training: Interleaved input / output (Java) Auto-graded programming assignments have numerous...
Questions
question
Mathematics, 24.09.2019 03:30
question
German, 24.09.2019 03:40
question
English, 24.09.2019 03:40
Questions on the website: 13722361