> Need help in Java! please help me finish writing this program?

Need help in Java! please help me finish writing this program?

Posted at: 2014-12-18 
There are so many ways to achieve the "if" condition. Simple one I think is:

if (dogName.startsWith("P")) {

// Write the name to the file.

outputFile.println(dogName);

}

checkout the string api http://docs.oracle.com/javase/7/docs/api... - methods that you can use on string (dogName) are here.

Hope it helps!

Dude i know i should be helping but i want to ask you a question. Where did you java. Im trying to learn it online but no one explains anything properly.

import java.util.*;

import java.io.*;

public class Program {

public static void main(String[] args) {

List names = read("Enter a male name for a dog? ");

saveTo("d:/temp/names.txt", filter(names));

}

private static List read(String message) {

List results = new ArrayList<>();

for (int i = 0; i < 20; i++) {

System.out.print(message);

Scanner keyboard = new Scanner(System.in);

String input = keyboard.nextLine();

results.add(input);

}

return results;

}

private static List filter(List items) {

List results = new ArrayList<>();

for (String item : items) {

if (item.toLowerCase().startsWith("p")) {

results.add(item);

}

}

return results;

}

private static void saveTo(String fileName, List items) {

File file = new File(fileName);

PrintWriter writer = null;

try {

writer = new PrintWriter(file);

for (String item : items) {

writer.println(item);

}

} catch (FileNotFoundException ex) {

ex.printStackTrace();

} finally {

if (writer != null) writer.close();

}

}

}