chore: remove unused repl-related configuration and placeholder files
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
class BankAccount {
|
||||
public String holder;
|
||||
public double balance;
|
||||
public BankAccount(String name, double initial) {
|
||||
this.holder = name;
|
||||
this.balance = initial;
|
||||
}
|
||||
public void deposit(double amount) {
|
||||
if (amount > 0) {
|
||||
this.balance = this.balance + amount;
|
||||
}
|
||||
}
|
||||
public boolean withdraw(double amount) {
|
||||
if (amount > 0 && amount <= this.balance) {
|
||||
this.balance = this.balance - amount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public double getBalance() {
|
||||
return this.balance;
|
||||
}
|
||||
public String info() {
|
||||
return this.holder + ": $" + this.balance;
|
||||
}
|
||||
}
|
||||
|
||||
BankAccount acc = new BankAccount("Alice", 1000.0);
|
||||
acc.info()
|
||||
acc.getBalance()
|
||||
|
||||
acc.deposit(500.0)
|
||||
acc.getBalance()
|
||||
|
||||
acc.withdraw(200.0)
|
||||
acc.getBalance()
|
||||
|
||||
acc.withdraw(2000.0)
|
||||
acc.getBalance()
|
||||
|
||||
acc.info()
|
||||
|
||||
%classes
|
||||
%whos
|
||||
%quit
|
||||
@@ -0,0 +1,20 @@
|
||||
int add(int a, int b) { return a + b; }
|
||||
int sub(int a, int b) { return a - b; }
|
||||
int mul(int a, int b) { return a * b; }
|
||||
int div(int a, int b) { return a / b; }
|
||||
int mod(int a, int b) { return a % b; }
|
||||
|
||||
add(100, 50)
|
||||
sub(100, 50)
|
||||
mul(100, 50)
|
||||
div(100, 50)
|
||||
mod(100, 7)
|
||||
|
||||
double sqrt(double x) { return Math.sqrt(x); }
|
||||
double pow(double base, double exp) { return Math.pow(base, exp); }
|
||||
|
||||
sqrt(144.0)
|
||||
pow(2.0, 8.0)
|
||||
|
||||
%methods
|
||||
%quit
|
||||
@@ -0,0 +1,28 @@
|
||||
int fib_recursive(int n) {
|
||||
if (n <= 1) return n;
|
||||
return fib_recursive(n - 1) + fib_recursive(n - 2);
|
||||
}
|
||||
|
||||
fib_recursive(0)
|
||||
fib_recursive(1)
|
||||
fib_recursive(5)
|
||||
fib_recursive(10)
|
||||
fib_recursive(15)
|
||||
|
||||
int fib_iterative(int n) {
|
||||
if (n <= 1) return n;
|
||||
int a = 0;
|
||||
int b = 1;
|
||||
for (int i = 2; i <= n; i++) {
|
||||
int temp = a + b;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
fib_iterative(20)
|
||||
fib_iterative(30)
|
||||
|
||||
%methods
|
||||
%quit
|
||||
@@ -0,0 +1,63 @@
|
||||
class Point {
|
||||
public double x;
|
||||
public double y;
|
||||
public Point(double px, double py) {
|
||||
this.x = px;
|
||||
this.y = py;
|
||||
}
|
||||
public double distanceTo(Point other) {
|
||||
double dx = this.x - other.x;
|
||||
double dy = this.y - other.y;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
}
|
||||
|
||||
class Circle {
|
||||
public Point center;
|
||||
public double radius;
|
||||
public Circle(Point c, double r) {
|
||||
this.center = c;
|
||||
this.radius = r;
|
||||
}
|
||||
public double area() {
|
||||
return 3.14159 * this.radius * this.radius;
|
||||
}
|
||||
public double circumference() {
|
||||
return 2.0 * 3.14159 * this.radius;
|
||||
}
|
||||
}
|
||||
|
||||
class Rectangle {
|
||||
public double width;
|
||||
public double height;
|
||||
public Rectangle(double w, double h) {
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
}
|
||||
public double area() {
|
||||
return this.width * this.height;
|
||||
}
|
||||
public double perimeter() {
|
||||
return 2.0 * (this.width + this.height);
|
||||
}
|
||||
public double diagonal() {
|
||||
return Math.sqrt(this.width * this.width + this.height * this.height);
|
||||
}
|
||||
}
|
||||
|
||||
Point p1 = new Point(0.0, 0.0);
|
||||
Point p2 = new Point(3.0, 4.0);
|
||||
p1.distanceTo(p2)
|
||||
|
||||
Circle c = new Circle(new Point(0.0, 0.0), 5.0);
|
||||
c.area()
|
||||
c.circumference()
|
||||
|
||||
Rectangle r = new Rectangle(3.0, 4.0);
|
||||
r.area()
|
||||
r.perimeter()
|
||||
r.diagonal()
|
||||
|
||||
%classes
|
||||
%whos
|
||||
%quit
|
||||
@@ -0,0 +1,34 @@
|
||||
boolean isPrime(int n) {
|
||||
if (n < 2) return false;
|
||||
if (n == 2) return true;
|
||||
if (n % 2 == 0) return false;
|
||||
for (int i = 3; i * i <= n; i = i + 2) {
|
||||
if (n % i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
isPrime(2)
|
||||
isPrime(17)
|
||||
isPrime(100)
|
||||
isPrime(997)
|
||||
|
||||
for (int i = 2; i <= 50; i++) {
|
||||
if (isPrime(i)) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
int countPrimes(int limit) {
|
||||
int count = 0;
|
||||
for (int i = 2; i <= limit; i++) {
|
||||
if (isPrime(i)) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
countPrimes(100)
|
||||
countPrimes(1000)
|
||||
|
||||
%methods
|
||||
%quit
|
||||
@@ -0,0 +1,48 @@
|
||||
void printArray(int[] arr) {
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
System.out.print(arr[i]);
|
||||
if (i < arr.length - 1) System.out.print(", ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
void bubbleSort(int[] arr) {
|
||||
int n = arr.length;
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
for (int j = 0; j < n - i - 1; j++) {
|
||||
if (arr[j] > arr[j + 1]) {
|
||||
int temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[] arr1 = {64, 34, 25, 12, 22, 11, 90};
|
||||
printArray(arr1)
|
||||
bubbleSort(arr1)
|
||||
printArray(arr1)
|
||||
|
||||
int findMin(int[] arr) {
|
||||
int min = arr[0];
|
||||
for (int i = 1; i < arr.length; i++) {
|
||||
if (arr[i] < min) min = arr[i];
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
int findMax(int[] arr) {
|
||||
int max = arr[0];
|
||||
for (int i = 1; i < arr.length; i++) {
|
||||
if (arr[i] > max) max = arr[i];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
int[] nums = {3, 1, 4, 1, 5, 9, 2, 6};
|
||||
findMin(nums)
|
||||
findMax(nums)
|
||||
|
||||
%methods
|
||||
%quit
|
||||
@@ -0,0 +1,53 @@
|
||||
String reverse(String s) {
|
||||
String result = "";
|
||||
for (int i = s.length() - 1; i >= 0; i--) {
|
||||
result = result + s.charAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
reverse("hello")
|
||||
reverse("Rava")
|
||||
|
||||
boolean isPalindrome(String s) {
|
||||
String lower = s.toLowerCase();
|
||||
int left = 0;
|
||||
int right = lower.length() - 1;
|
||||
while (left < right) {
|
||||
if (lower.charAt(left) != lower.charAt(right)) {
|
||||
return false;
|
||||
}
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
isPalindrome("radar")
|
||||
isPalindrome("hello")
|
||||
isPalindrome("Racecar")
|
||||
|
||||
int countChar(String s, char c) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (s.charAt(i) == c) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
countChar("mississippi", 's')
|
||||
countChar("hello world", 'l')
|
||||
|
||||
String repeat(String s, int n) {
|
||||
String result = "";
|
||||
for (int i = 0; i < n; i++) {
|
||||
result = result + s;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
repeat("ab", 5)
|
||||
repeat("*", 10)
|
||||
|
||||
%methods
|
||||
%quit
|
||||
Reference in New Issue
Block a user