Hi everyone,
I have an assignment due which I can't figure out. If anyone can help me that would be great.. Here is the description: Write a program that will read words from an external file and determines if the word falls between dinosaur and walrus in the dictionary. Print out the word and either between or not between. Continue processing the words until end of file is reached.
And here is the external file:
Vampire
Monkay
Elephant
Ape
Lion
Hippopotamus
Ant
Zebra
Yak
Antelope
Dingo
Whale
My code looks like this:
The output should look like this:
Vampire between
Monkey between
Elephant between
Ape not between
Lion between
Hippopotamus between
Ant not between
Zebra not between
Yak not between
Antelope not between
Dingo not between
Whale not between
However, my output currently looks like this:
Vampire not between
Monkay not between
Elephant not between
Ape not between
Lion between
Hippopotamus not between
Ant not between
Zebra not between
Yak between
Antelope not between
Dingo not between
Whale not between
Any help would be fantastic.. I'm sure it's just a small error in the code..
I have an assignment due which I can't figure out. If anyone can help me that would be great.. Here is the description: Write a program that will read words from an external file and determines if the word falls between dinosaur and walrus in the dictionary. Print out the word and either between or not between. Continue processing the words until end of file is reached.
And here is the external file:
Vampire
Monkay
Elephant
Ape
Lion
Hippopotamus
Ant
Zebra
Yak
Antelope
Dingo
Whale
My code looks like this:
import java.util.Scanner; import java.io.*; public class InBetween { public static void main(String args[]) { try { FileInputStream words = new FileInputStream("prog505c.dat"); DataInputStream in = new DataInputStream(words); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while((strLine = br.readLine()) != null) { char[] animals = strLine.toCharArray(); String dino = "Dinosaur"; char[] dinosaur = dino.toCharArray(); String wal = "Walrus"; char[] walrus = wal.toCharArray(); int ResultOne = animals.toString().compareToIgnoreCase(walrus.toString()); int ResultTwo = animals.toString().compareToIgnoreCase(dinosaur.toString()); if (ResultOne < 0 && ResultTwo > 0) { System.out.println(strLine + " between"); } else { System.out.println(strLine + " not between"); } } } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
The output should look like this:
Vampire between
Monkey between
Elephant between
Ape not between
Lion between
Hippopotamus between
Ant not between
Zebra not between
Yak not between
Antelope not between
Dingo not between
Whale not between
However, my output currently looks like this:
Vampire not between
Monkay not between
Elephant not between
Ape not between
Lion between
Hippopotamus not between
Ant not between
Zebra not between
Yak between
Antelope not between
Dingo not between
Whale not between
Any help would be fantastic.. I'm sure it's just a small error in the code..