Modify the code to read integer values from the keyboard, store them into a 15 element array, then write the array into a file named userin.txt
Modify the code to read integer values from the keyboard, store them into a 15 element array, then write the array into a file named userin.txt
CODE
import java.util.Scanner;
import java.io.*;
public class Storeintoarr {
public static void main(String[] args) throws IOException
{
File loopfile = new File("fileLoop.txt");
Scanner getAll = new Scanner( loopfile );
// connect a Scanner to the file
int num = 0, square = 0;
int[] items = new int[10];
int i = 0;
while(getAll.hasNextInt()){
num = getAll.nextInt();
square = num * num ;
//System.out.println("The square of " + num + " is " + square);
items[i] = num;
System.out.println("items[i] is " + items[i]);
i = i + 1;
}
getAll.close();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps