Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Add yourself in this file if you are a contributor for Hacktoberfest 2018

- Radu Stochitoiu
- Aravind V. Nair ([@AravindVNair99](https://github.com/AravindVNair99)), Computer Science enthusiast mainly interested in web development and cybersecurity [Portfolio Website](https://aravindvnair99.firebaseapp.com), [Blog](https://aravindvnair1999.blogspot.com)
29 changes: 29 additions & 0 deletions Java/algorithms/PasswordGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Generate random password of given length

import java.util.Random;
import java.util.Scanner;

public class PasswordGenerator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the length of the password you require:\n");
System.out.println(generatePswd(sc.nextInt()));
sc.close();
}

static char[] generatePswd(int len) {
System.out.println("\nYour password is:\n");
String charsCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String chars = "abcdefghijklmnopqrstuvwxyz";
String nums = "0123456789";
String symbols = "!@#$%^&*_=+-/€.?<>)";
String passSymbols = charsCaps + chars + nums + symbols;
Random rnd = new Random();
char[] password = new char[len];
int index = 0;
for (int i = 0; i < len; i++) {
password[i] = passSymbols.charAt(rnd.nextInt(passSymbols.length()));
}
return password;
}
}
27 changes: 27 additions & 0 deletions Java/algorithms/ReverseArrayUsingStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//Reverse an array using stack

import java.util.Scanner;
import java.util.Stack;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
System.out.println("Enter the size of the array:");
n = sc.nextInt();
Stack<Integer> st = new Stack<Integer>();
int[] a = new int[n];
System.out.println("\nEnter the elements of the array:");
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
st.push(a[i]);
}
System.out.println("\nArray after reversing:");
for (int i = 0; i < n; i++) {
System.out.println(a[i] = st.pop());
}
sc.close();
}
}
102 changes: 102 additions & 0 deletions Java/data-structures/CircularQueueUsingArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import java.util.Scanner;

public class CircularQueueUsingArray {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter total no of elements to be in the queue: ");
int maxSize = input.nextInt();
CircularQueue queue = new CircularQueue(maxSize);
int select;
int term = 0;
while (term == 0) {
System.out.print(
"\nOption:\tTo Do:\n1\tTo enqueue element.\n2\tTo dequeue element.\n3\tTo Display the Queue elements.\n4\tTo Exit the Program.\n\nEnter your option:- ");
select = input.nextInt();
switch (select) {
case 1: {
System.out.print("\nEnter element to insert in the queue: ");
int ele = input.nextInt();
queue.enqueue(ele);
break;
}
case 2: {
queue.dequeue();
break;
}
case 3: {
queue.display();
break;
}
case 4: {
term = 1;
System.out.println("\nSee you next time!");
input.close();
break;
}
default:
System.out.println("\nEnter a valid option.");
}
}
}
}

class CircularQueue {
int maxSize;
int rear;
int front;
int aQueue[];
{
rear = -1;
front = -1;
}

CircularQueue(int maxSize) {
this.maxSize = maxSize;
this.aQueue = new int[maxSize];
}

void enqueue(int item) {
if (((rear + 1) % maxSize) == front) {
System.out.println("\nQueue is full");
} else {
if (rear == front && front == -1) {
front += 1;
}
rear = (rear + 1) % maxSize;
aQueue[rear] = item;
}
}

void dequeue() {
if (rear == front && rear == -1) {
System.out.println("\nQueue is empty.");
} else {
int item = aQueue[front];
if (rear == front) {
rear = -1;
front = -1;
} else {
front = (front + 1) % maxSize;
}
System.out.println(item + " is deQueued from the Queue");
}
}

void display() {
int tempfront = front;
if (rear == front && rear == -1) {
System.out.println("\nQueue is Empty.");
} else {
System.out.println("\nThe contents of the queue are:- ");
for (int i = 0; i < maxSize; i++) {
if (tempfront != rear) {
System.out.println(aQueue[tempfront]);
tempfront = (tempfront + 1) % maxSize;
} else {
System.out.println(aQueue[rear]);
break;
}
}
}
}
}