Hello,
I'm stuck with my assignment again which is to:
1. Read in all 20 lines of text from a file and store them.
2. Display all the 20 lines of text on the screen
3. Display every other line in upper case (so the first, then the third etc), you don’t need to display the other line at all (i.e. no output of second, fourth etc.)
4. Display the number of characters in each line of text and display the average of the characters for all 20 lines of text.
5. Display the first 10 characters from each line of text
I'm now stuck with task 4 i've got as far as to display the number of letters in each line but can't quite figgure out how to display the average of the characters for all 20 lines
The code I have now is:
/** assignment one reading 20 lines from a file. */ import java.util.Scanner; import java.io.File; class alice{ public static void main (String args[]) throws Exception { File myFile = new File("alice.txt"); Scanner Scan = new Scanner(myFile); String []aliceline=new String[20]; String uppercase; for (int line=0;line<20; line++) {aliceline[line] = Scan.nextLine(); System.out.println(aliceline[line]); } System.out.println(""); for (int odd = 0; odd < 20; odd++){ System.out.println(aliceline[odd].toUpperCase()); odd = odd+1; } System.out.println(""); for (int b = 0; b < 20; b++) { System.out.println(aliceline[b].length()); System.out.println(); /** I need to work the average in this part of the code */ } Scan.close(); } }
Any help with this will be much appriciated