## Jupyter at Bryn Mawr College

Public notebooks: /services/public/dblank / Experiments
In [ ]:
import java.util.*;
int n = 12;
int p = 0, c = 1, a;
List<Integer> list = new ArrayList<>();

while (n-- > 0) {
a = p + c;
p = c;
c = a;
}

System.out.println(list);

In [ ]:
int var1 = 2
int meth2() {
return var1+2;
}

++var1

class class3 {
int meth4() {
return var1 * meth2();
}
}

System.out.println(new class3().meth4())

In [ ]:
int passCnt
int failCnt
int unexpectedCnt

void check(boolean pass) {
if (pass) {
System.out.println("pass");
++passCnt;
} else {
System.out.println("FAIL");
++failCnt;
}
}

void expectError(boolean huh) {
System.out.println("Should not be here, should be error");
++unexpectedCnt;
}

int m() { return 100; }
int m(int x) { return x; }
int m(int x, int y) { return x * y; }

check(m(5,4) == 20);
check(m(7) == 7);
check(m() == 100);
int m(int x) { return x * 100; }
check(m(3) == 300);
check(m() == 100);
check(m(5,4) == 20);
int m() { return 1234; }
check(m() == 1234);
double m(int x, int y) { return x + y; }
check(m(2,3) == 5.0);
double m(double x, double y) { return y - x; }
check(m(2.0,3.0) == 1.0);
check(m(2,3) == 5.0);
System.out.println((passCnt==10 && failCnt==0 && unexpectedCnt==0)?
"Test passes!" :
"Test FAILED! Pass: " + passCnt + ", Fail: " + failCnt + ", Unexpected: " + unexpectedCnt)

In [3]:
int passCnt;
int failCnt;
int unexpectedCnt;
/*
void check(boolean pass) {
if (pass) {
System.out.println("pass");
++passCnt;
} else {
System.out.println("FAIL");
++failCnt;
}
}
*/
/*
void expectError(boolean huh) {
System.out.println("Should not be here, should be error");
++unexpectedCnt;
}
*/
int x;
//int mu() { return x * 4; }
//class C {
//  String v() { return "#" + mu(); }
//}
//new C();
//check($1.v().equals("#0")) /* int x = 10 check($1.v().equals("#40"))
C c = new C()
check(c.v().equals("#40"))
int mu() { return x * 3; }
check(c.v().equals("#30"))
class C {
String v() { return "@@" + mu(); }
}
check($1.v().equals("@@30")) c = new C() check(c.v().equals("@@30")) double x = 2.5 check(x == 2.5) */ /* expectError(mu() == 30) c = new C() expectError(c.v().equals("@@30")) int mu() { return (int) (x * 10); } check(mu() == 25) c = new C() check(c.v().equals("@@25")) double mu() { return x * 2.0; } check(mu() == 5.0) check($1.v().equals("@@5.0"))
c = new C()
check(c.v().equals("@@5.0"))
class C {
Object v() { return mu(); }
}
//check($1 == null) //TODO fix update of temp vars C d = new C() check(d.v().equals(5.0)) System.out.println((passCnt==13 && failCnt==0 && unexpectedCnt==0)? "Test passes!" : "Test FAILED! Pass: " + passCnt + ", Fail: " + failCnt + ", Unexpected: " + unexpectedCnt) */ System.out.println("Ok")   System.out.println("Ok") Ok  In [2]: System.out.println("Ok")   System.out.println("Ok") Ok  In [5]: class Tree { Tree left; Tree right; int value; Tree(int value) { this.value = value; } } Tree tree = new Tree(10); tree.left = new Tree(2);   tree.left = new Tree(2); | Expression value is: Tree@33e5ccce | assigned to temporary variable$1 of type Tree


Out[5]:
Tree@33e5ccce
In [6]:
tree.left.value

 tree.left.value
|  Expression value is: 2
|    assigned to temporary variable $2 of type int  Out[6]: 2 In [3]: $2

 $2 | Variable$2 of type int has value 2


Out[3]:
2
In [1]:
System.out.println(y)

 System.out.println(y)
|  Error:
|  cannot find symbol
|    symbol:   variable y
|  System.out.println(y)
|                     ^


In [2]:
System.out.println(1/0)

 System.out.println(1/0)
|  java.lang.ArithmeticException thrown: / by zero
|        at (#9:1)


In [5]:
System.out.println("ok")

 System.out.println("ok")
ok


In [20]:
%%python

kernel.javawrapper.child.send("varia")
kernel.javawrapper.child.sendcontrol('t')
kernel.javawrapper.child.sendeof()

In [17]:
System.out.println("ok")

 variaSystem.out.println("ok")
|  Error:
|  package variaSystem does not exist
|  variaSystem.out.println("ok")
|  ^-------------^


In [2]:
/help

 /help
Type a Java language expression, statement, or declaration.
Or type one of the following commands:

/l  or /list [all]                -- list the source you have typed
/seteditor <executable>    -- set the external editor command to use
/e  or /edit <name or id>         -- edit a source entry referenced by name or id
/s  or /save [all|history] <file> -- save the source you have typed
/o  or /open <file>               -- open a file as source input
/v  or /vars                      -- list the declared variables and their values
/m  or /methods                   -- list the declared methods and their signatures
/c  or /classes                   -- list the declared classes
/x  or /exit                      -- exit the REPL
/r  or /reset                     -- reset everything in the REPL
/f  or /feedback <level>          -- feedback information: off, concise, normal, verbose, default, or ?
/p  or /prompt                    -- toggle display of a prompt
/cp or /classpath <path>          -- add a path to the classpath
/h  or /history                   -- history of what you have typed
/setstart <file>           -- read file and set as the new start-up definitions
/savestart <file>          -- save the default start-up definitions to the file
/?  or /help                      -- this help message

Supported shortcuts include:
<tab>       -- show possible completions for the current text
Shift-<tab> -- for current method or constructor invocation, show a synopsis of the method/constructor


In [22]:
/help

 /classes


In [8]:
/help

 /help
Type a Java language expression, statement, or declaration.
Or type one of the following commands:

/l  or /list [all]                -- list the source you have typed
/seteditor <executable>    -- set the external editor command to use
/e  or /edit <name or id>         -- edit a source entry referenced by name or id
/s  or /save [all|history] <file> -- save the source you have typed
/o  or /open <file>               -- open a file as source input
/v  or /vars                      -- list the declared variables and their values
/m  or /methods                   -- list the declared methods and their signatures
/c  or /classes                   -- list the declared classes
/x  or /exit                      -- exit the REPL
/r  or /reset                     -- reset everything in the REPL
/f  or /feedback <level>          -- feedback information: off, concise, normal, verbose, default, or ?
/p  or /prompt                    -- toggle display of a prompt
/cp or /classpath <path>          -- add a path to the classpath
/h  or /history                   -- history of what you have typed
/setstart <file>           -- read file and set as the new start-up definitions
/savestart <file>          -- save the default start-up definitions to the file
/?  or /help                      -- this help message

Supported shortcuts include:
<tab>       -- show possible completions for the current text
Shift-<tab> -- for current method or constructor invocation, show a synopsis of the method/constructor


In [ ]:
%%python


In [1]:
int variable_name = 1;

 int variable_name = 1;
|  Added variable variable_name of type int with initial value 1


In [3]:
variable_name

 variable_name
|  Variable variable_name of type int has value 1


Out[3]:
1
In [4]:
variable_name

 variable_name
|  Variable variable_name of type int has value 1


Out[4]:
1
In [5]:
variable_name

 variable_name
|  Variable variable_name of type int has value 1


Out[5]:
1
In [9]:
variable_name

 variable_name
|  Variable variable_name of type int has value 1


Out[9]:
1