Skip to content

Commit 67b137e

Browse files
authored
Add files via upload
1 parent 8e56c18 commit 67b137e

8 files changed

+404
-0
lines changed

training/JavaInput.java

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package Java_Technical_Training;
2+
3+
import java.util.*;
4+
5+
public class JavaInput {
6+
public static void main(String[] args) throws Exception {
7+
main();
8+
main(4);
9+
// int first = Integer.parseInt(args[0]);
10+
// int second = Integer.parseInt(args[1]);
11+
// ! if one value is missing then array index out of bounds error will generated
12+
13+
// int result = first + second;
14+
// System.out.println(result);
15+
16+
int sum = 0;
17+
for (int i = 0; i < args.length; i++) {
18+
sum += Integer.parseInt(args[i]);
19+
}
20+
System.out.println("sum: " + Integer.toString(sum));
21+
22+
System.out.println("Enter the name : ");
23+
Scanner sc = new Scanner(System.in);
24+
String x = sc.nextLine();
25+
sc.nextLine();
26+
System.out.println("Enter the age : ");
27+
int y = sc.nextInt();
28+
System.out.println(x);
29+
System.out.println(y);
30+
31+
sc.close();
32+
33+
}
34+
35+
// private static Scanner Scanner(InputStream in) {
36+
// return null;
37+
// }
38+
39+
public static void main(int m) {
40+
System.out.println("The power of " + m + " is : " + m * m);
41+
}
42+
43+
public static void main() {
44+
System.out.println("This is user defined main ");
45+
}
46+
}

training/JavaLeapYear.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Java_Technical_Training;
2+
3+
import java.util.*;
4+
5+
public class JavaLeapYear {
6+
public static void main(String[] args) {
7+
Scanner sc = new Scanner(System.in);
8+
int year = sc.nextInt();
9+
boolean leap = false;
10+
if (year % 4 == 0) {
11+
if (year % 100 == 0) {
12+
if (year % 400 == 0)
13+
leap = true;
14+
else
15+
leap = false;
16+
} else
17+
leap = true;
18+
} else
19+
leap = false;
20+
if (leap)
21+
System.out.println(year + " is a leap year.");
22+
else
23+
System.out.println(year + " is not a leap year.");
24+
sc.close();
25+
}
26+
}

training/LcmGcd.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package Java_Technical_Training;
2+
3+
import java.util.Scanner;
4+
5+
public class LcmGcd {
6+
public static void main(String[] args) {
7+
Scanner sc = new Scanner(System.in);
8+
9+
System.out.print("Enter the first number : ");
10+
int x = sc.nextInt();
11+
System.out.print("Enter the first number : ");
12+
int y = sc.nextInt();
13+
14+
System.out.println("The numbers are : " + x + " are " + y);
15+
int gcd = 0;
16+
17+
for (int i = 1; i <= x && i <= y; i++) {
18+
if (x % i == 0 && y % i == 0) {
19+
gcd = i;
20+
}
21+
}
22+
System.out.println("The greatest common divisor is : " + gcd);
23+
int lcm = x * y / gcd;
24+
System.out.println("The least common divisor is : " + lcm);
25+
26+
sc.close();
27+
}
28+
}

training/PrimeNumber.java

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package Java_Technical_Training;
2+
3+
import java.util.*;
4+
5+
public class PrimeNumber {
6+
public static void main(String[] args) {
7+
8+
System.out.print("Enter the number : ");
9+
Scanner sc = new Scanner(System.in);
10+
int n = sc.nextInt();
11+
12+
boolean flag = false;
13+
flag = isPrime1(n);
14+
System.out.println("Is " + n + " is prime using first function : " + flag);
15+
flag = false;
16+
flag = isPrime2(n);
17+
System.out.println("Is " + n + " is prime using efficient function : " + flag);
18+
flag = false;
19+
flag = isPrime3(n);
20+
System.out.println("Is " + n + " is prime using optimized function : " + flag);
21+
sc.close();
22+
}
23+
24+
static boolean isPrime1(int n) {
25+
for (int i = 2; i < n; i++) {
26+
if (n % i == 0)
27+
return false;
28+
}
29+
return true;
30+
}
31+
32+
static boolean isPrime2(int n) {
33+
for (int i = 2; i <= Math.sqrt(n); i++) {
34+
if (n % i == 0)
35+
return false;
36+
}
37+
return true;
38+
}
39+
40+
static boolean isPrime3(int n) {
41+
if (n == 1)
42+
return false;
43+
if ((n == 2 || n == 3))
44+
return true;
45+
if (n % 2 == 0 || n % 3 == 0)
46+
return false;
47+
48+
for (int i = 5; i < Math.sqrt(n); i = i + 6) {
49+
if (n % i == 0 || n % (i + 2) == 0)
50+
return false;
51+
}
52+
return true;
53+
}
54+
55+
}

training/javaOperators.java

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package Java_Technical_Training;
2+
3+
class Parents {
4+
5+
}
6+
7+
class A extends Parents {
8+
9+
}
10+
11+
class B extends Parents {
12+
13+
}
14+
15+
public class javaOperators {
16+
public static void main(String[] args) {
17+
// ! Types of operators:
18+
/*
19+
* Arithmetic operators (+,-,*,/)
20+
* Logical operators (&&, ||, ! )
21+
* Unary operators => (++x, --x, x++, x--)
22+
* Arithmetic Assignment operators (+=, -=, *=, /=)
23+
* Ternary operators (? : )
24+
* Relational operators (>,<, <=, >=, ==, = , !=)
25+
* Bitwise operators (&, !, ^, ~)
26+
* shifting operators are part of Bitwise operators ( >>, <<, >>>)
27+
*/
28+
29+
byte a = 10;
30+
byte b = 34;
31+
32+
byte c = (byte) (a + b);
33+
// ? type conversion
34+
35+
Parents obj = new A();
36+
Parents obj1 = new B();
37+
38+
System.out.println(obj instanceof A);
39+
System.out.println(obj1 instanceof B);
40+
System.out.println(obj1 instanceof A);
41+
System.out.println(obj instanceof B);
42+
43+
System.out.println(c);
44+
45+
System.out.println("Logcal operators");
46+
System.out.println("100 & 39 == " + (100 & 39));
47+
System.out.println("100 | 39 == " + (100 | 39));
48+
Boolean res = true;
49+
System.out.println(!res);
50+
System.out.println(!!res);
51+
52+
// ? when we use Arithmetic Assignment operators, we don't need to typecast the
53+
// variables
54+
System.out.println("Arithmetic Assignment operators: " + a + " " + b);
55+
System.out.println(a += b);
56+
System.out.println(a -= b);
57+
System.out.println(a *= b);
58+
59+
System.out.println("Ternary operators");
60+
System.out.println(" a is " + a);
61+
String aa = a >= 50 ? "it is greater than 50" : "it is lower than ";
62+
System.out.println(aa);
63+
64+
System.out.println(" a is " + a);
65+
System.out.println(" a is " + (a >> 1));
66+
System.out.println(" a is " + (a >> 2));
67+
System.out.println(" a is " + (a >> 3));
68+
System.out.println(" \n a is " + a);
69+
System.out.println(" a is " + (a << 1));
70+
System.out.println(" a is " + (a << 2));
71+
72+
// ! difference between right shift and unsigned right shift
73+
74+
int tt = 15;
75+
System.out.println(" tt = " + (tt >> 2));
76+
System.out.println(" tt = " + (tt >>> 2));
77+
// ? change left most digit while using unsigned right shift
78+
}
79+
}

training/javaString.java

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package Java_Technical_Training;
2+
3+
import java.util.Date;
4+
5+
public class javaString {
6+
7+
/**
8+
* @param args
9+
*/
10+
public static void main(String[] args) {
11+
12+
String name = "Ankit";
13+
String name2 = "Ankit";
14+
15+
System.out.println(name + name2);
16+
17+
String name3 = new String("Ankit");
18+
System.out.println(name3);
19+
String name4 = new String("Amit");
20+
System.out.println(name4);
21+
22+
// ! Immutablility of strings
23+
24+
String type = "Shoes";
25+
System.out.println(type);
26+
// String sql = "Select * from products where type = " + type;
27+
StringBuffer sql = new StringBuffer("Select * from products where type = "); // ? capacity = 16 characters
28+
// sql = "Select * from products where type = " + type; // ? capacity = 16
29+
// characters + length of
30+
31+
System.out.println("length = " + sql.length() + "\n capacity = " + sql.capacity());
32+
33+
double price = 3999;
34+
sql.append("and price >= ").append(price);
35+
36+
sql.append("my name is ankit nainwal and that is all ").append(price);
37+
System.out.println(sql);
38+
System.out.println("length = " + sql.length() + "\n capacity = " + sql.capacity());
39+
40+
/*
41+
* //! Stringbuffer creates buffer storage with 16 characters
42+
*
43+
* string bulider comes after java 5, it is not synchronized and do not
44+
* obtains locks
45+
* to use string builder we can make synchronized block usng lock
46+
* ?
47+
* StringBuilder str = new StringBuilder("hello");
48+
* System.out.println(str);
49+
*/
50+
51+
/*
52+
* reference type : String, StringBuffer, StringBulder, Wrapper types(it wraps
53+
* all the primitive types of data types)
54+
*
55+
* here Integer b is immutable, and belongs to wrapper class of Integer
56+
*
57+
*
58+
*
59+
*/
60+
61+
int a = 10;
62+
Integer b = 20;
63+
Float c = 34.3f;
64+
Double t = 454.45;
65+
Boolean istrue = true;
66+
Character ch = 'A';
67+
68+
System.out.println(a + " " + b + " " + " " + c + " " + t + " " + istrue + " " + ch);
69+
System.out.println("Binary of a is : " + Integer.toBinaryString(a));
70+
71+
System.out.println(Character.isLowerCase('A'));
72+
73+
// LinkedList<String> list = new LinkedList<>();
74+
75+
Date d = new Date();
76+
System.out.println("The Date is : " + d);
77+
78+
}
79+
}

training/nestedLoops.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package Java_Technical_Training;
2+
3+
public class nestedLoops {
4+
public static void main(String[] args) {
5+
6+
for (int i = 1; i <= 3; i++) {
7+
for (int j = 1; j <= 3; j++) {
8+
System.out.println("I is " + i + " and J is " + j);
9+
}
10+
}
11+
}
12+
// int n=5;
13+
// for(int i =0; i<=n; i++){
14+
// System.out.println();
15+
// for(int j = 0; j<=i; j){
16+
// System.out.println(j);
17+
// }
18+
// }
19+
// }
20+
}

0 commit comments

Comments
 (0)