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
After solving steps 1 and 2 i soon found myself hitting a brick wall again with step 3, everything i've looked at on the net just seems to be to complicated for what i need to do with this step.
The code I have so far is:
/** assignment one reading 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]); } { uppercase = aliceline; /** i need this part to read all the even lines from the array*/ System.out.println(uppercase); } Scan.close(); } }
I have tried lots of things such as uppercase=aliceline[0][2] or [0+2] but it just won't work and i'm now at a loss.
If anone could please help me with this........