QUESTION IMAGE
Question
jump to level 1
integer numinput is read from input representing the number of integers to be read next. a for loop iterates from 0 to numinput - 1. inside the loop:
- assign variable inputval with an integer read from input.
- output quantity: followed by inputval, ending with a newline.
click here for example
1 import java.util.scanner;
2
3 public class readdata {
4 public static void main(string args) {
5 scanner scnr = new scanner(system.in);
6 int numinput;
7 int inputval;
8 int i;
9
10 numinput = scnr.nextint();
11
12 for (i = 0; i < numinput; ++i) {
13
14 / your code goes here /
15
Step1: Read input integer for loop count
numInput = scnr.nextInt();
Step2: Iterate through loop
for (i = 0; i < numInput; ++i) {
inputVal = scnr.nextInt();
System.out.println("Quantity: " + inputVal);
}Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
import java.util.Scanner;
public class ReadData {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numInput;
int inputVal;
int i;
numInput = scnr.nextInt();
for (i = 0; i < numInput; ++i) {
inputVal = scnr.nextInt();
System.out.println("Quantity: " + inputVal);
}
}
}