Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All java codes from basics to advance DSA #206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions Add Code Here/Java/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Add Code Here/Java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Add Code Here/Java/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Add Code Here/Java/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.debug.settings.onBuildFailureProceed": true,
"jdk.runConfig.vmOptions": "--enable-preview --source 22"
}
Binary file not shown.
21 changes: 21 additions & 0 deletions Add Code Here/Java/Basics/ArithmeticOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import java.util.*;

public class ArithmeticOperation{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a first element:");
int a = sc.nextInt();
System.out.print("Enter a first element:");
int b = sc.nextInt();
int diff = a-b;
int sum = a+b;
int multi = a*b;
System.out.println("Addition of " + a + " and " + b + " is: " + sum);
System.out.println("Subtraction of " + a + " and " + b + " is: " + diff);
System.out.println("Multiplication of " + a + " and " + b + " is: " + multi);
String name = sc.nextLine();
System.out.println(name);

}
}
18 changes: 18 additions & 0 deletions Add Code Here/Java/Basics/Characterpattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;

public class Characterpattern {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no of lines you want to print: ");
int a = sc.nextInt();
char ch= 'A';
for(int i=1;i<=a;i++){
for(int j=1;j<=i;j++){
System.out.print(ch);
ch++;
}
System.out.println("");
}

}
}
15 changes: 15 additions & 0 deletions Add Code Here/Java/Basics/Datatype.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import com.sun.jdi.BooleanType;

public class Datatype {
public static void main(String[] args) {
byte b = 8;
char ch ="b";
boolean var = true;
float price = 10.501;
int a = 25;
short n = 240;

}

}
17 changes: 17 additions & 0 deletions Add Code Here/Java/Basics/Halfpyramid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Scanner;


public class Halfpyramid {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no of lines you want to print: ");
int a = sc.nextInt();
for(int i=1;i<=a;i++){
for(int j=1;j<=i;j++){
System.out.print(j);
}
System.out.println("");
}

}
}
Binary file added Add Code Here/Java/Basics/HelloWorld.class
Binary file not shown.
8 changes: 8 additions & 0 deletions Add Code Here/Java/Basics/TypeConversion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class TypeConversion {
public static void main(String[] args) {
int a = 10;
float b = 10.52;
System.out.println(int));
System.out.println(float);
}
}
16 changes: 16 additions & 0 deletions Add Code Here/Java/Basics/TypePromotion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import java.util.Scanner;

public class TypePromotion {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char a = 'a';
char b = 'b';
System.out.println((int)a);
System.out.println((int)b);

byte d = 5;
d=(byte)(d);
System.out.println(d);
}
}
Binary file added Add Code Here/Java/Basics/Typecasting.class
Binary file not shown.
21 changes: 21 additions & 0 deletions Add Code Here/Java/Basics/Typecasting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Scanner;

public class Typecasting {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
float a = 25.10f;
int b=(int)a;
System.out.print("Float value "+a+" is type cast into integer:");
System.out.println(b);

char ch1 = 'a';
char ch2 = 'b';
int num1 = ch1;
int num2 = ch2;
System.out.print("The value of a&b coverted to the Integer: ");
System.out.print(num1+ " ");
System.out.println(num2+ " ");


}
}
26 changes: 26 additions & 0 deletions Add Code Here/Java/Basics/conditionalstatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import java.util.Scanner;

public class conditionalstatement {
public static void main (String[]args){
Scanner sc = new Scanner(System.in);
//System.out.print("enter your age:");
// int a = sc.nextInt();
// if(a>=18){
// System.out.println("you can vote and drive");
// }
// else{
// System.out.println("you can not vote and drive");
// }
System.out.print("Enter A:");
int a=sc.nextInt();
System.out.print("Enter b:");
int b=sc.nextInt();
if (a>b){
System.out.println("a is big");
}
else{
System.out.println("b is greater");
}
}
}
Binary file added Add Code Here/Java/Basics/fibonachiseries.class
Binary file not shown.
17 changes: 17 additions & 0 deletions Add Code Here/Java/Basics/fibonachiseries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//fibonachi series in java
public class fibonachiseries{
public static void main(String[]args){
//initialize 3 variables
int n1,n2,n3,i,count=10;
n1=0;
n2=1;
System.out.print(n1+" "+n2);
//using for loop here the value of the i=2 because we already defined n1 and n2
for(i=2;i<=count;++i){
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
}
}
10 changes: 10 additions & 0 deletions Add Code Here/Java/Basics/helloworld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//first we define class in java
public class helloworld{
// creating function
public static void main(String[] args) {
//output function in java
System.out.println("hello sidharth");
}
}

// boiler plate
18 changes: 18 additions & 0 deletions Add Code Here/Java/Basics/invertedstar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;

public class invertedstar {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of lines you want to print: ");
int a = sc.nextInt();

for (int i = 1; i <= a; i++) {
for (int j = 1; j <= (a - i + 1); j++) {
System.out.print("*");
}
System.out.println(); // Move to the next line after printing stars in the current row
}

sc.close(); // Close the scanner
}
}
29 changes: 29 additions & 0 deletions Add Code Here/Java/Basics/operators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@




public class operators {
public static void main(String[] args){
int a=10;
int b=2;
System.out.println("addition is :" + (a+b));
System.out.println("subtraction is :" + (a-b));
System.out.println("divison is :" + (a/b));
System.out.println("multiplication is :" + (a*b));
System.out.println("modulo (remainder)is :" + (a%b));



int c=10;
//int d=++c;
// int e=c;
//int f=--c;
int g=c--;
System.out.println(c);
//System.out.println(d);
//System.out.println(e);
// System.out.println(f);
System.out.println(g);

}
}
19 changes: 19 additions & 0 deletions Add Code Here/Java/Basics/primeno.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import java.util.Scanner;

public class primeno{
public static void main(String[] args){

scanner imp = new Scanner(System.in);

System.out.println("FIND GIVEN NO. IS PRIME OR NOT");
System.out.print("Enter the number:");
int a = sc.next.int();






}
}
8 changes: 8 additions & 0 deletions Add Code Here/Java/Basics/print stars injava.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class stars{
public static void main(String[] args) {
System.out.println("*");
System.out.println("**");
System.out.println("***");
System.out.println("****");
}
}
20 changes: 20 additions & 0 deletions Add Code Here/Java/Basics/starpattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Scanner;

public class starpattern{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.print("Enter the no of lines you want to print: ");
int a = sc.nextInt();


for(int i=1;i<=a;i++){

for(int j=1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}

}
6 changes: 6 additions & 0 deletions Add Code Here/Java/Basics/tempCodeRunnerFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
55 changes: 55 additions & 0 deletions Add Code Here/Java/Bitwise manipulation/BitManipulation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package Bitwise manipulation;


public class BitManipulation {

// Get the i-th bit of a number
public static int getIthBit(int num, int i) {
int mask = 1 << i;
return (num & mask) != 0 ? 1 : 0;
}

// Clear the i-th bit of a number
public static int clearIthBit(int num, int i) {
int mask = ~(1 << i);
return num & mask;
}

// Update the i-th bit of a number to a given value (0 or 1)
public static int updateIthBit(int num, int i, int value) {
num = clearIthBit(num, i); // First clear the i-th bit
int mask = (value << i);
return num | mask;
}

// Clear a range of bits from position i to j (inclusive)
public static int clearRangeOfBits(int num, int i, int j) {
int left = (~0) << (j + 1); // All 1s till position j and 0s after that
int right = (1 << i) - 1; // All 0s till position i and 1s after that
int mask = left | right; // Combine to create a mask with 0s in range i to j
return num & mask;
}

// Count the number of set bits (1s) in a number
public static int countSetBits(int num) {
int count = 0;
while (num != 0) {
count += (num & 1); // Check the least significant bit
num >>= 1; // Right shift the number
}
return count;
}

public static void main(String[] args) {
int num = 29; // Example number in binary: 11101

System.out.println("Original number: " + num);
System.out.println("Get 3rd bit: " + getIthBit(num, 3));
System.out.println("Clear 2nd bit: " + clearIthBit(num, 2));
System.out.println("Update 1st bit to 0: " + updateIthBit(num, 1, 0));
System.out.println("Clear range of bits from 1 to 3: " + clearRangeOfBits(num, 1, 3));
System.out.println("Count of set bits: " + countSetBits(num));
}
}


Binary file added Add Code Here/Java/DSA/BuyOrSellStocks.class
Binary file not shown.
Loading