Last active
October 4, 2015 23:33
-
-
Save twhite96/105b36e60161d7b6a6cd to your computer and use it in GitHub Desktop.
Java Program for class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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