Before you can being using UNIX, you need to get onto a unix computer. If you are working with your own machine do the following:
cd | What directory are you in? | |
What is the contents of this directory? | ||
cd / | What directory are you in? | |
What is the contents of this directory? | ||
cd ~ | What directory are you in? | |
What is the contents of this directory? | ||
cd /home/YOU | (Replace YOU with your login name) What directory are you in? | |
What is the difference between this command and the previous one? | ||
ls /home/gtowell/Public/206 | What did this command do? | |
What is the difference between this and cd /home/gtowell/Public/206 followed by ls | ||
cd /home/gtowell/Private | What directory are you in? | |
You should have noted that you could not cd into this directory. UNIX has a concept of "permissions". These specify whether you are allow into a directory, and weather yo can read or write a file. Generally you have permission to do anything in the directory /home/YOU and anywhere beneath that. Also, because I have given you permission, you can read the files in /home/gtowell/Public/206. Through the semester I will put files there for you to copy. Other places you will likely not have access to. |
cd ~ mkdir cs206
public class EchoCount { public static void main(String[] args) { new EchoCount().echo(); } public EchoCount() { } public void echo() { try (BufferedReader br = new BufferedReader(new FileReader("/home/gtowell/Public/206/lab01/descent.txt"));) { int lineCount=0; while (true) { String l=br.readLine(); lineCount++; } System.out.println("Lines read " + lineCount); } catch (FileNotFoundException fnf) { System.err.println("Could not open the file" + fnf); } catch (IOException ioe) { System.err.println("Reading problem" + ioe); } } }
public void doUI() { int total=0; Scanner ss = new Scanner(System.in); while (total < 100) { System.out.print("Enter an integer (or Exit to quit)"); String ll = ss.nextLine(); if ("Exit".equals(ll)) break; try { int ii = Integer.parseInt(ll); total += ii; } catch (NumberFormatException ee) { System.err.println(ll + " is not an integer"); } } }Write your program to use this method.
Once you program works, extend it so that the user is asked for input at most 10 times.
1 1 1.0 1 2 2.0 2 3 1.5 3 5 1.6666666666666667 5 8 1.6 8 13 1.625 13 21 1.6153846153846154 21 34 1.619047619047619 34 55 1.6176470588235294 55 89 1.6181818181818182 89 144 1.6179775280898876 144 233 1.6180555555555556 233 377 1.6180257510729614 377 610 1.6180371352785146 610 987 1.618032786885246 987 1597 1.618034447821682 1597 2584 1.6180338134001253 2584 4181 1.618034055727554 4181 6765 1.6180339631667064 6765 10946 1.6180339985218033Here is the the core code for computing the fibonacci sequence. You will need to write a more code to make this useful.
int n_2=1; int n_1=1; for (int i=1; i<20; i++) { int nI = n_2 + n_1; n_1 = n_2; n_2 = nI; }When calculating the golden mean (1.618....) you will want to watch out for an issue with integer versus floating point division