18.2k views
2 votes
Write a while loop to read integers from input until -1 is read. For each integer read before -1, add the integer multiplied by five to the vector of input integers.

1 Answer

2 votes

Final answer:

A while loop can be used to read integers from input until -1 is read and for each integer read before -1, add the integer multiplied by five to the vector of input integers.

Step-by-step explanation:

A while loop can be used to read integers from input until -1 is read and for each integer read before -1, add the integer multiplied by five to the vector of input integers.

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
ArrayList inputIntegers = new ArrayList();
Scanner scanner = new Scanner(System.in);
int number;

while ((number = scanner.nextInt()) != -1) {
inputIntegers.add(number * 5);
}

for (int i = 0; i < inputIntegers.size(); i++) {
System.out.println(inputIntegers.get(i));
}
}
}

User Sharell
by
8.0k points