Skip to content

Commit f03517a

Browse files
committed
added bitwise operators folder
1 parent 44c07c6 commit f03517a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2055
-2007
lines changed

Diff for: 01 - First Program/Coercion.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import java.util.Scanner;
2-
public class Coercion{
3-
public static void main(String[] args){
4-
Scanner input = new Scanner(System.in);
5-
// float num = input.nextFloat(); //even if we give integer, we get a float as int < float
6-
// System.out.println(num);
7-
8-
// Type Casting
9-
int val = (int)(65.55f);
10-
11-
// Automatic type promotion in expressions;
12-
int a = 257;
13-
byte b = (byte)(a); //This will give 256%257 = 1
14-
System.out.println(b);
15-
}
1+
import java.util.Scanner;
2+
public class Coercion{
3+
public static void main(String[] args){
4+
Scanner input = new Scanner(System.in);
5+
// float num = input.nextFloat(); //even if we give integer, we get a float as int < float
6+
// System.out.println(num);
7+
8+
// Type Casting
9+
int val = (int)(65.55f);
10+
11+
// Automatic type promotion in expressions;
12+
int a = 257;
13+
byte b = (byte)(a); //This will give 256%257 = 1
14+
System.out.println(b);
15+
}
1616
}

Diff for: 01 - First Program/Conditions.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
public class Conditions{
2-
public static void main(String[] args){
3-
int a = 11;
4-
if(a == 10){
5-
System.out.println("Hello World");
6-
}
7-
else{
8-
System.out.println("Namaste world");
9-
}
10-
}
1+
public class Conditions{
2+
public static void main(String[] args){
3+
int a = 11;
4+
if(a == 10){
5+
System.out.println("Hello World");
6+
}
7+
else{
8+
System.out.println("Namaste world");
9+
}
10+
}
1111
}

Diff for: 01 - First Program/Input.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import java.util.Scanner;
2-
public class Input{
3-
public static void main(String[] args){
4-
Scanner input = new Scanner(System.in);
5-
System.out.print("Please enter some input");
6-
int rollno = input.nextInt();
7-
System.out.println("Your roll number is " + rollno);
8-
9-
10-
int a = 10; //Here a is the identifier and 10 is the literal
11-
12-
int b = 2_50_00_000; //This is how we can write 2,50,00,000
13-
System.out.println(b);
14-
15-
String name = input.next();
16-
System.out.println(name);
17-
}
1+
import java.util.Scanner;
2+
public class Input{
3+
public static void main(String[] args){
4+
Scanner input = new Scanner(System.in);
5+
System.out.print("Please enter some input");
6+
int rollno = input.nextInt();
7+
System.out.println("Your roll number is " + rollno);
8+
9+
10+
int a = 10; //Here a is the identifier and 10 is the literal
11+
12+
int b = 2_50_00_000; //This is how we can write 2,50,00,000
13+
System.out.println(b);
14+
15+
String name = input.next();
16+
System.out.println(name);
17+
}
1818
}

Diff for: 01 - First Program/Main.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import java.util.Scanner;
2-
3-
public class Main{
4-
public static void main(String[] args){ //int main() in java is like this
5-
// System.out.println("Hello World!"); //printf or cout of java
6-
// System.out.println(args[2]); //it prints the output based on command line
7-
Scanner input = new Scanner(System.in); //Scanner is a class in the java.util package. It is used to take input
8-
System.out.println(input.nextInt()); //Inputs an integer
9-
System.out.println(input.next()); //Inputs the first word of a sentence
10-
System.out.println(input.nextLine()); //Inputs the whole sentence
11-
}
1+
import java.util.Scanner;
2+
3+
public class Main{
4+
public static void main(String[] args){ //int main() in java is like this
5+
// System.out.println("Hello World!"); //printf or cout of java
6+
// System.out.println(args[2]); //it prints the output based on command line
7+
Scanner input = new Scanner(System.in); //Scanner is a class in the java.util package. It is used to take input
8+
System.out.println(input.nextInt()); //Inputs an integer
9+
System.out.println(input.next()); //Inputs the first word of a sentence
10+
System.out.println(input.nextLine()); //Inputs the whole sentence
11+
}
1212
}

Diff for: 01 - First Program/Primitive.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
public class Primitive{
2-
public static void main(String[] args) {
3-
//String is not a primitive, i.e. it can be further broken into characters.
4-
//Integers are primitive as we cannot break them further;
5-
//Char is aldo a primitive as it cannot be broken further
6-
7-
// int rollno = 64;
8-
// String name = "Mohit";
9-
// char letter = 'a';
10-
// float marks = 98.77f;
11-
// double largeDecimalNumbers = 87646.68546;
12-
// long largeIntegerValues = 5976465656565646L; //L implies that its a long integer, not just a integer boolean check = true;
13-
// boolean check = true;
14-
15-
}
16-
}
1+
public class Primitive{
2+
public static void main(String[] args) {
3+
//String is not a primitive, i.e. it can be further broken into characters.
4+
//Integers are primitive as we cannot break them further;
5+
//Char is also a primitive as it cannot be broken further
6+
7+
// int rollno = 64;
8+
// String name = "Mohit";
9+
// char letter = 'a';
10+
// float marks = 98.77f;
11+
// double largeDecimalNumbers = 87646.68546;
12+
// long largeIntegerValues = 5976465656565646L; //L implies that its a long integer, not just a integer boolean check = true;
13+
// boolean check = true;
14+
15+
}
16+
}

Diff for: 01 - First Program/Sum.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
2-
import java.util.Scanner;
3-
public class Sum{
4-
public static void main(String[] agrs){
5-
Scanner input = new Scanner(System.in);
6-
System.out.print("Enter the first number: ");
7-
int val1 = input.nextInt();
8-
System.out.print("Enter the second number: ");
9-
int val2 = input.nextInt();
10-
int sum = val1 + val2;
11-
System.out.println("The sum of val1 and val2 is " + sum);
12-
}
1+
2+
import java.util.Scanner;
3+
public class Sum{
4+
public static void main(String[] agrs){
5+
Scanner input = new Scanner(System.in);
6+
System.out.print("Enter the first number: ");
7+
int val1 = input.nextInt();
8+
System.out.print("Enter the second number: ");
9+
int val2 = input.nextInt();
10+
int sum = val1 + val2;
11+
System.out.println("The sum of val1 and val2 is " + sum);
12+
}
1313
}

Diff for: 01 - First Program/Temperature.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import java.util.Scanner;
2-
public class Temperature{
3-
public static void main(String[] args){
4-
Scanner input = new Scanner(System.in);
5-
System.out.println("Enter the temperature in Celcius");
6-
float tempC = input.nextFloat();
7-
float tempF = ( tempC * 9/5) + 32;
8-
System.out.println("Temperature in Faranheit is: " + tempF);
9-
}
1+
import java.util.Scanner;
2+
public class Temperature{
3+
public static void main(String[] args){
4+
Scanner input = new Scanner(System.in);
5+
System.out.println("Enter the temperature in Celcius");
6+
float tempC = input.nextFloat();
7+
float tempF = ( tempC * 9/5) + 32;
8+
System.out.println("Temperature in Faranheit is: " + tempF);
9+
}
1010
}

Diff for: 01 - First Program/loops.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
public class loops{
2-
public static void main(String[] args){
3-
// while loop
4-
int count = 1;
5-
while(count != 5){
6-
System.out.println(count);
7-
count++;
8-
}
9-
10-
11-
//For loop
12-
for(count = 0; count<5; count++){
13-
System.out.println(count);
14-
}
15-
}
1+
public class loops{
2+
public static void main(String[] args){
3+
// while loop
4+
int count = 1;
5+
while(count != 5){
6+
System.out.println(count);
7+
count++;
8+
}
9+
10+
11+
//For loop
12+
for(count = 0; count<5; count++){
13+
System.out.println(count);
14+
}
15+
}
1616
}

Diff for: 02 - Conditionals & Loops/Calculator.java

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
import java.util.Scanner;
2-
public class Calculator{
3-
public static void main(String[] args){
4-
Scanner in = new Scanner(System.in);
5-
6-
int ans = 0;
7-
// Take the input from the user till the user does not print X or x
8-
while(true){
9-
System.out.print("Enter the operator: ");
10-
char op = in.next().trim().charAt(0);
11-
if(op == '+' || op == '*' || op == '-' || op == '/' || op == '%'){
12-
//input two numbers:
13-
System.out.print("Enter two numbers: ");
14-
int num1 = in.nextInt();
15-
int num2 = in.nextInt();
16-
if(op == '+'){
17-
ans = num1 + num2;
18-
}
19-
else if(op == '-'){
20-
ans = num1 - num2;
21-
}
22-
else if(op == '*'){
23-
ans = num1 * num2;
24-
}
25-
else if(op == '/'){
26-
if(num2 != 0){
27-
ans = num1 / num2;
28-
}
29-
}
30-
else if(op == '%'){
31-
ans = num1 % num2;
32-
}
33-
}
34-
else if(op != 'X' || op != 'x'){
35-
break;
36-
}
37-
else{
38-
System.out.println("Invalid Operation");
39-
}
40-
System.out.println("The answer is: " + ans);
41-
}
42-
}
1+
import java.util.Scanner;
2+
public class Calculator{
3+
public static void main(String[] args){
4+
Scanner in = new Scanner(System.in);
5+
6+
int ans = 0;
7+
// Take the input from the user till the user does not print X or x
8+
while(true){
9+
System.out.print("Enter the operator: ");
10+
char op = in.next().trim().charAt(0);
11+
if(op == '+' || op == '*' || op == '-' || op == '/' || op == '%'){
12+
//input two numbers:
13+
System.out.print("Enter two numbers: ");
14+
int num1 = in.nextInt();
15+
int num2 = in.nextInt();
16+
if(op == '+'){
17+
ans = num1 + num2;
18+
}
19+
else if(op == '-'){
20+
ans = num1 - num2;
21+
}
22+
else if(op == '*'){
23+
ans = num1 * num2;
24+
}
25+
else if(op == '/'){
26+
if(num2 != 0){
27+
ans = num1 / num2;
28+
}
29+
}
30+
else if(op == '%'){
31+
ans = num1 % num2;
32+
}
33+
}
34+
else if(op != 'X' || op != 'x'){
35+
break;
36+
}
37+
else{
38+
System.out.println("Invalid Operation");
39+
}
40+
System.out.println("The answer is: " + ans);
41+
}
42+
}
4343
}

Diff for: 02 - Conditionals & Loops/CaseCheck.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import java.util.Scanner;
2-
public class CaseCheck{
3-
public static void main(String[] args){
4-
Scanner in = new Scanner(System.in);
5-
char ch = in.next().trim().charAt(0); //Here trim removes all the extra spaces, charAt gives the character at the given index;
6-
// System.out.println(ch);
7-
8-
if (ch >= 'a' && ch <= 'z') {
9-
System.out.println("Lower Case");
10-
}
11-
else if(ch >= 'A' && ch <= 'Z'){
12-
System.out.println("Upper Case");
13-
}
14-
15-
}
1+
import java.util.Scanner;
2+
public class CaseCheck{
3+
public static void main(String[] args){
4+
Scanner in = new Scanner(System.in);
5+
char ch = in.next().trim().charAt(0); // Here trim removes all the extra spaces, charAt gives the character at the given index;
6+
// System.out.println(ch);
7+
8+
if (ch >= 'a' && ch <= 'z') {
9+
System.out.println("Lower Case");
10+
}
11+
else if(ch >= 'A' && ch <= 'Z'){
12+
System.out.println("Upper Case");
13+
}
14+
15+
}
1616
}

Diff for: 02 - Conditionals & Loops/CountingOccurances.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import java.util.Scanner;
2-
public class CountingOccurances{
3-
public static void main(String[] args){
4-
Scanner in = new Scanner(System.in);
5-
System.out.print("Enter the original number and the number whose occurance you want: ");
6-
int num = in.nextInt();
7-
int key = in.nextInt();
8-
int count = 0;
9-
while(num!=0){
10-
int rem = num % 10;
11-
if(rem == key) count++;
12-
num = num/10;
13-
}
14-
System.out.println(count);
15-
}
1+
import java.util.Scanner;
2+
public class CountingOccurances{
3+
public static void main(String[] args){
4+
Scanner in = new Scanner(System.in);
5+
System.out.print("Enter the original number and the number whose occurance you want: ");
6+
int num = in.nextInt();
7+
int key = in.nextInt();
8+
int count = 0;
9+
while(num!=0){
10+
int rem = num % 10;
11+
if(rem == key) count++;
12+
num = num/10;
13+
}
14+
System.out.println(count);
15+
}
1616
}

0 commit comments

Comments
 (0)