Amazon Interview Question
Developer Program EngineersCountry: India
Interview Type: Written Test
import java.io.*;
import java.util.ArrayList;
public class amazone {
public static void main(String[] args) throws IOException
{
File file=new File("file4.txt");
boolean EOF=false;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input Please :");
int content=Integer.parseInt(br.readLine());
DataOutputStream dos1=new DataOutputStream(new FileOutputStream(file,true));
dos1.writeInt(content);
dos1.close();
@SuppressWarnings("resource")
DataInputStream dis=new DataInputStream(new FileInputStream(file));
int count=0;
ArrayList<Integer> arr=new ArrayList<Integer>();
while(!EOF)
{
try
{
count=dis.readInt();
System.out.println(count);
arr.add(count);
}
catch (EOFException e)
{
EOF = true;
}
}
System.out.println(arr);
int size=arr.size();
for(int i=1;i<size;i++)
{
int diff=(arr.get(i))-(arr.get(i-1));
System.out.println(diff);
}
}
}
- IgorBrown31 October 16, 2014