Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.io.*;
- import static java.lang.System.*;
- class Animals{
- String name;
- String color;
- int age;
- Animals( String name, String color, int age ) {
- this.name = name;
- this.color = color;
- this.age = age;
- }
- }
- public class Program {
- public static void main ( String[] args ) throws IOException {
- ArrayList<Animals> u = new ArrayList<Animals>();
- Scanner uni = new Scanner(System.in);
- out.println("N = ");
- int n = uni.nextInt();
- String nume, color;
- int age;
- for ( int i = 0; i < n; i++ ) {
- out.println("Animal number " + (i+1) );
- out.println("Name - ");
- nume = uni.next();
- out.println("Color - ");
- color = uni.next();
- out.println("Age - ");
- age = uni.nextInt();
- u.add(new Animals(nume,color,age));
- }
- writing(u);
- }
- public static void writing ( ArrayList<Animals> a ) throws IOException {
- FileWriter uni = new FileWriter("Animals.txt");
- for (Animals i : a ) {
- uni.write(i.name + " " + i.color + " " + i.age);
- uni.write("\n");
- uni.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment