-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaceArray.java
More file actions
27 lines (21 loc) · 876 Bytes
/
ReplaceArray.java
File metadata and controls
27 lines (21 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.io.*;
public class ReplaceArray {
public static void main (String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your ten numbers: ");
//lets read whatever is in our buffer separaetd by spaces and assign them into an array
String[] inputValues = bufferedReader.readLine().split(" ");
//create a new array that will store the input values
int[] arr = new int[10];
for (int i=0; i < inputValues.length; i++){
arr[i] = Integer.parseInt(inputValues[i]);
//check if the number is a negative or a positive
if (arr[i] < 0 || arr[i] == 0 ){
arr[i] = 1 ;
}
}//end of for loop that loops through the input values
for (int x=0; x < arr.length; x++){
System.out.println("arr["+x+"]="+arr[x]);
}//print the value at each index
}
}