Skip to content

Instantly share code, notes, and snippets.

@twhite96
Last active October 4, 2015 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twhite96/105b36e60161d7b6a6cd to your computer and use it in GitHub Desktop.
Save twhite96/105b36e60161d7b6a6cd to your computer and use it in GitHub Desktop.
Java Program for class
import java.util.Scanner;
import java.io.*;
public class White
{
public static void main(String[] args) throws IOException
{
// Gets the PrintWriter and Scanner classes
PrintWriter file = new PrintWriter("names.txt");
Scanner keyboard = new Scanner(System.in);
// Gets data and writes it to a file
for (int i = 1; i <= 3; i++)
{
//Gets name of friend
System.out.print("Enter the name of friend " + "number " + i + ": ");
String friendName = keyboard.nextLine();
file.println(friendName);
}
System.out.print("Enter the filename: ");
String filename = keyboard.nextLine();
System.out.println(friendName);
FileWriter fw = new FileWriter("names.txt", true);
PrintWriter pw = new PrintWriter(fw);
for (int i = 4; i <= 6; i++)
{
//Gets name of friend
System.out.print("Enter the name of friend " + "number " + i + ": ");
String friendName = keyboard.nextLine();
file.println(friendName);
}
System.out.print("Enter the filename: ");
String filename = keyboard.nextLine();
System.out.println(friendName);
file.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment