-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-08-26 17:12:12.080171 new snippets
- Loading branch information
1 parent
9fd3943
commit 50b08db
Showing
39 changed files
with
1,030 additions
and
932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//date: 2024-08-26T16:46:54Z | ||
//url: https://api.github.com/gists/415476a667aad137ad41f7de8877aae7 | ||
//owner: https://api.github.com/users/RamshaMohammed | ||
|
||
import java.util.Arrays; | ||
|
||
class Array_Rotations { | ||
static void left_rotate(int[] arr, int n) { | ||
n = n % arr.length; | ||
for (int i = 0; i < n; i++) { | ||
int copy = arr[0]; | ||
for (int j = 1; j < arr.length; j++) { | ||
arr[j - 1] = arr[j]; | ||
} | ||
arr[arr.length - 1] = copy; | ||
System.out.println(Arrays.toString(arr)); | ||
} | ||
} | ||
|
||
static void right_rotate(int[] arr, int n) { | ||
n = n % arr.length; | ||
for (int i = 0; i < n; i++) { | ||
int copy = arr[arr.length - 1]; | ||
for (int j = arr.length - 1; j > 0; j--) { | ||
arr[j] = arr[j - 1]; | ||
} | ||
arr[0] = copy; | ||
System.out.println(Arrays.toString(arr)); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
int[] arr = {8, 4, 5, 1, 7, 3, 2, 4}; | ||
System.err.println("Original array: " + Arrays.toString(arr)); | ||
left_rotate(arr, 1); | ||
arr = new int[]{8, 4, 5, 1, 7, 3, 2, 4}; | ||
right_rotate(arr, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//date: 2024-08-26T16:49:19Z | ||
//url: https://api.github.com/gists/b29aeaabf6b03dcde670c3c7b18786b3 | ||
//owner: https://api.github.com/users/RamshaMohammed | ||
|
||
import java.util.Scanner; | ||
|
||
class LessBalanceException extends Exception { | ||
public LessBalanceException() | ||
{ | ||
System.out.println("lessBalance exception"); | ||
} | ||
} | ||
|
||
public class BankingApplication { | ||
|
||
public static void main(String[] args) { | ||
BankAccount account = new BankAccount(10000); | ||
try { | ||
account.deposit(5000); | ||
account.checkBalance(); | ||
account.withdraw(3500); | ||
account.checkBalance(); | ||
account.withdraw(900); | ||
|
||
} catch (LessBalanceException e) { | ||
System.out.println("Exception caught: " + e.getMessage()); | ||
} finally { | ||
System.out.println("Final balance is:"); | ||
account.checkBalance(); | ||
} | ||
} | ||
} | ||
|
||
class BankAccount { | ||
private double balance; | ||
|
||
public BankAccount(double initialBalance) { | ||
this.balance = initialBalance; | ||
} | ||
|
||
public void deposit(double amount) { | ||
if (amount > 0) { | ||
balance += amount; | ||
System.out.println("Successfully deposited " + amount); | ||
} else { | ||
System.out.println("Deposit amount is"); | ||
} | ||
} | ||
|
||
public void withdraw(double amount) throws LessBalanceException { | ||
if (amount > balance) { | ||
throw new LessBalanceException(); | ||
} else if (amount <= 0) { | ||
System.out.println("Withdrawal amount is"); | ||
} else { | ||
balance -= amount; | ||
System.out.println("Successfully withdrwn: " + amount); | ||
} | ||
} | ||
|
||
public void checkBalance() { | ||
System.out.println("Current balance: " + balance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//date: 2024-08-26T16:49:19Z | ||
//url: https://api.github.com/gists/b29aeaabf6b03dcde670c3c7b18786b3 | ||
//owner: https://api.github.com/users/RamshaMohammed | ||
|
||
import java.util.Scanner; | ||
|
||
class InvalidAgeException extends Exception { | ||
public InvalidAgeException() | ||
{ | ||
System.out.println("To open Bank Account using Age"); | ||
} | ||
} | ||
|
||
class BankAccount_Registration { | ||
public static void main(String[] args) { | ||
Scanner s = new Scanner(System.in); | ||
System.out.println("Enter your age to open a bank account:"); | ||
int age = s.nextInt(); | ||
|
||
try { | ||
validateAge(age); | ||
System.out.println("Congrats! Your bank account has been opened."); | ||
} catch (InvalidAgeException e) { | ||
System.out.println("Exception caught: " + e.getMessage()); | ||
} finally { | ||
System.out.println("Bank account registration process completed."); | ||
s.close(); | ||
} | ||
} | ||
public static void validateAge(int age) throws InvalidAgeException { | ||
if (age < 18 || age > 100) | ||
{ | ||
throw new InvalidAgeException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//date: 2024-08-26T16:52:44Z | ||
//url: https://api.github.com/gists/334da33b328a058c4a5bacd60a2340cf | ||
//owner: https://api.github.com/users/RamshaMohammed | ||
|
||
class thread extends Thread | ||
{ | ||
public void run() | ||
{ | ||
try { | ||
for(int i=1;i<=7;i++) | ||
{ | ||
System.out.println("Ramsha"); | ||
Thread.sleep(1000); | ||
} | ||
} | ||
catch(InterruptedException e) | ||
{ | ||
System.out.println("I like to explore new places"); | ||
} | ||
} | ||
} | ||
public class Interrupt { | ||
public static void main(String[] args) | ||
{ | ||
thread t1 = new thread(); | ||
t1.start(); | ||
t1.interrupt(); | ||
System.out.println(t1.isInterrupted()); | ||
System.out.println(t1.interrupted()); | ||
for(int i = 0;i<=6;i++) | ||
{ | ||
System.out.println("I am from vijayawada"+i); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//date: 2024-08-26T16:46:54Z | ||
//url: https://api.github.com/gists/415476a667aad137ad41f7de8877aae7 | ||
//owner: https://api.github.com/users/RamshaMohammed | ||
|
||
public class Max { | ||
public static void main(String[] args) { | ||
int[] arr = {12,3,7,19,8}; | ||
int[] r = Max(arr); | ||
System.out.println("Max1: " + r[0]); | ||
System.out.println("Max2: " + r[1]); | ||
} | ||
|
||
public static int[] Max(int[] arr) { | ||
int max1 = Integer.MIN_VALUE; | ||
int max2 = Integer.MIN_VALUE; | ||
|
||
for (int i = 0; i < arr.length; i++) { | ||
if (arr[i] > max1) { | ||
max2 = max1; | ||
max1 = arr[i]; | ||
} else if (arr[i] > max2) { | ||
max2 = arr[i]; | ||
} | ||
} | ||
return new int[]{max1,max2}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//date: 2024-08-26T16:46:54Z | ||
//url: https://api.github.com/gists/415476a667aad137ad41f7de8877aae7 | ||
//owner: https://api.github.com/users/RamshaMohammed | ||
|
||
public class Min { | ||
public static void main(String[] args) { | ||
int[] arr = {12,3,7,19,8}; | ||
int[] r = Min(arr); | ||
System.out.println("Min1: " + r[0]); | ||
System.out.println("Min2: " + r[1]); | ||
} | ||
|
||
public static int[] Min(int[] arr) { | ||
int min1 = Integer.MAX_VALUE; | ||
int min2 = Integer.MAX_VALUE; | ||
|
||
for (int i = 0; i < arr.length; i++) { | ||
if (arr[i] < min1) { | ||
min2 = min1; | ||
min1 = arr[i]; | ||
} else if (arr[i] < min2) { | ||
min2 = arr[i]; | ||
} | ||
} | ||
return new int[]{min1,min2}; | ||
} | ||
} |
Oops, something went wrong.