To start an ssh session
ssh UNIX_NAME@goldengate.cs.brynmawr.eduwhere UNIX_NAME is your UNIX account name. When prompted, enter your password. Unlike every other Unix command you have used, this one does not complete quickly, rather it effectively opens a terminal on the machine goldengate. So you end up with a terminal onto the UNIX servers that is running inside a terminal that is running on your laptop!
Once you have the ssh terminal running, set up -- on the UNIX servers -- for todays lab.
cd cd CS113 mkdir Lab3
If you have not done so already, open and log into a UNIX machine in the lab and open a terminal. Verify that the Lab3 directory exists.
Finally, close your ssh session (on your laptop) by entering exit.
Using ssh means that, in the future, you do not have to set foot in the lab when you want to submit an assignment (if you are doing your work on a laptop). Everything that you would do on a lab computer can be done from within an ssh session.
$ java Reverse 1234 4321 $java Reverse 19103 30191Once your program has read n as a runtime argument, it should use the following algorithm to reverse the digits and store the value in the variable r:
initialize r to 0 while n != 0 set d to the last digit of n multiply r by 10 and add d divide n by 10When this algorithm terminates, you can print the variable r to see the digits in reverse. The trick here is figuring out how to set d to the last digit of n. Think about the different arithmetic operators we have seen in class this semester!
double d = Math.random(); int number = (int)(d*100);Question: what happens when you make the line above just int number = (int)d*100? Why?
Next you will need to get input from the user. Here is a little program to et a single number from a user.
import java.util.Scanner; public class Scanr { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); System.out.println("Enter an integer"); int enteredInteger = scnr.nextInt(); System.out.println("You entered " + enteredInteger); } }
For example, here is the output from two runs of my guessing program (which I cleverly named "Guessing").
$ java Guessing Enter a number in 0..100 50 Too High Enter a number in 0..100 254 Too High Enter a number in 0..100 25 Too low Enter a number in 0..100 40 Too High Enter a number in 0..100 30 Too low Enter a number in 0..100 35 Got it $ java Guessing Enter a number in 0..100 50 Too High Enter a number in 0..100 25 Too low Enter a number in 0..100 37 Too low Enter a number in 0..100 44 Too High Enter a number in 0..100 40 Too High Enter a number in 0..100 38 Too low Enter a number in 0..100 39 Got it