Programming class:
===================
[Link] or Even:
-----------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 11;
if (a % 2 == 0) {
[Link]("Even number");
} else {
[Link]("Odd num");
}
}
}
Console:
Odd num
[Link] 1 to 100 Even number:
---------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 2 == 0) {
[Link](i+" ");
}
}
}
}
Console:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52
54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
[Link] 1 to 10 odd number:
-----------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
if (i % 2 == 1) {
[Link](i+" ");
}
}
}
}
Console:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51
53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
[Link] number from 1 to 5:
----------------------------------
The factorial of a number is the product of all the numbers from 1 to
that number. For example, factorial of 5 is equal to 1 * 2 * 3 * 4 * 5 =
120.
The factorial of negative numbers do not exist and the factorial of 0 is
1.
package [Link];
public class Employee {
public static void main(String[] args) {
int fact = 1;
for (int i = 1; i <= 5; i++) {
fact = fact * i;//1*1=1*2=2*3=6
}
[Link](fact);
}
}
Console:
120
[Link] number count from 1 to 100:
------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 100; i++) {
if (i % 2 == 0) {
count = count + 1;
}
}
[Link](count);
}
}
Console:
50
[Link] number count from 1 to 1000:
--------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 1000; i++) {
if (i % 2 == 1) {
count = count + 1;
}
}
[Link](count);
}
}
Console:
500
[Link] of Even number from 1 to 500:
----------------------------------------
sum is a adding of numbers.
package [Link];
public class Employee {
public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 500; i++) {
if (i % 2 == 0) {
count = count + i;
}
}
[Link](count);
}
}
Console:
62750
[Link] of Odd number from 1 to 100:
--------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 100; i++) {
if (i % 2 == 1) {
count = count + i;
}
}
[Link](count);
}
}
Console:
2500
[Link] of the number from 1 to 600:
----------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 600; i++) {
count = count + i;
}
[Link](count);
}
}
Console:
180300
[Link] the number:
----------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 123;
int i = 0, j = 0;
while (a > 0) {
i = a % 10;
j = (j * 10) + i;
a = a / 10;
}
[Link](j);
}
}
Console:
321
[Link] number or not:
------------------------------
A palindromic number is a number (such as 16461) that remains the same
when its digits are reversed.
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 141, n = 0;
int i = 0, j = 0;
n = a;
while (a > 0) {
i = a % 10;
j = (j * 10) + i;
a = a / 10;
}
if (n == j) {
[Link]("palindrome number");
} else {
[Link]("Not a palindrome number....");
}
}
}
Console:
palindrome number
[Link] the palindrome number from 1 to 1000:
----------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
for (int k = 1; k <= 1000; k++) {
int a = k, n = 0;
int i = 0, j = 0;
n = a;
while (a > 0) {
i = a % 10;
j = (j * 10) + i;
a = a / 10;
}
if (n == j) {
[Link](j);
}
}
}
}
Console:
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101 111 121 131 141 151 161
171 181 191 202 212 222 232 242 252 262 272 282 292 303 313 323 333 343
353 363 373 383 393 404 414 424 434 444 454 464 474 484 494 505 515 525
535 545 555 565 575 585 595 606 616 626 636 646 656 666 676 686 696 707
717 727 737 747 757 767 777 787 797 808 818 828 838 848 858 868 878 888
898 909 919 929 939 949 959 969 979 989 999
[Link] number or not:
------------------------------
An Armstrong number of three digits is an integer such that the sum of
the cubes of its digits is equal to the number itself.
For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 153, n = 0;
int i = 0, j = 0;
n = a;
while (a > 0) {
i = a % 10;
j = j + (i * i * i);
a = a / 10;
}
if (n == j) {
[Link]("Amstrong");
} else {
[Link]("Not a amstrong number");
}
}
}
Console:
Amstrong
[Link] amstrong number from 1 to 600:
----------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
for (int k = 1; k <= 600; k++) {
int a = k, n = 0;
int i = 0, j = 0;
n = a;
while (a > 0) {
i = a % 10;
j = j + (i * i * i);
a = a / 10;
}
if (n == j) {
[Link](j);
}
}
}
}
Console:
1
153
370
371
407
[Link] the digit:
-------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 12567893, count = 0;
while (a > 0) {
a = a / 10;
count = count + 1;
}
[Link](count);
}
}
Console:
8
[Link] of the digit:
-----------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 1238, sum = 0;
int i = 0;
while (a > 0) {
i = a % 10;
sum = sum + i;
a = a / 10;
}
[Link](sum);
}
}
Console:
14
[Link] the 2 number with using 3rd variable name:
-----------------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 10, b = 20, temp;
temp = a;//temp=10
a = b;//a=20
b = temp;//b=10
[Link](a);
[Link](b);
}
}
Console:
20
10
[Link] the 2 number without using 3rd variable name:
----------------------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 10, b = 20;
a = a + b;//a=30
b = a - b;//b=10
a = a - b;//a=20
[Link](a);
[Link](b);
}
}
Console:
20
10
[Link] series from 1 to 10:
--------------------------------------
The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
The next number is found by adding up the two numbers before it:
the 2 is found by adding the two numbers before it (1+1),
the 3 is found by adding the two numbers before it (1+2),
the 5 is (2+3),
and so on!
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 0, b = 1, c = 0;
for (int i = 1; i <= 10; i++) {
c = a + b;//c=2
[Link](c);
a = b;//a=1
b = c;//b=2
}
}
}
Console:
1
2
3
5
8
13
21
34
55
89
[Link] the fabanocii series sum from 1 to 10:
----------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a = 0, b = 1, c = 0;
int sum = 0;
for (int i = 1; i <=10 ; i++) {
c= a+b;
sum = sum + c;
a=b;
b=c;
}
[Link](sum);
}
}
Console:
231
[Link] the string:
-------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome";
String res = "";
for (int i = [Link]() - 1; i >= 0; i--) {
char ch = [Link](i);
res = res + ch;
}
[Link](res);
}
}
Console:
emocleW
21.1 Split the String
=======================
public static void main(String[] args) {
String name="yuvaraj king dort";
String [] sh=[Link](" ");
for(String a : sh)
[Link](a);
}
console:
yuvaraj
king
dort
[Link] String or not:
------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "madam";
String res = "";
for (int i = [Link]() - 1; i >= 0; i--) {
char ch = [Link](i);
res = res + ch;
}
if ([Link](name)) {
[Link]("Palindrome string");
} else {
[Link]("Not palindrome string");
}
}
}
Console:
Palindrome string
[Link] order:
--------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a[] = { 10, 100, 90, 20, 40 }, temp;
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for (int i = 0; i < [Link]; i++) {
[Link](a[i]);
}
}
}
Console:
10
20
40
90
100
23.1 Asending array value less second value
public static void main(String[] args) {
int a[] = { 10, 100, 90, 20, 40 }, temp;
int b[] = new int [[Link]-1];
for(int i=0;i<[Link]-1;i++) {
b[i]=a[i]-a[i+1];
[Link](b[i]);
}
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (b[i] > b[j]) {
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
for (int i = 0; i < [Link]; i++) {
[Link](b[i]+"after");
}
Console:
-90
10
70
-20
-90after
-20after
10after
70after
23.1 Asending array value less second value and find minmum and maximum
number
public static void main(String[] args) {
int a[] = { 10, 100, 90, 20, 40 }, temp;
int b[] = new int [[Link]-1];
for(int i=0;i<[Link]-1;i++) {
b[i]=a[i]-a[i+1];
[Link](b[i]);
}
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (b[i] < b[j]) {
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
for (int i = 0; i < [Link]; i++) {
[Link](b[i]+"after");
}
[Link]("Min no:" + b[0]);
[Link]("Max no:" + b[[Link] - 1]);
}
Console:
-90
10
70
-20
-90after
-20after
10after
70after
Min no:-90
Max no:70
[Link] Order:
-----------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a[] = { 10, 100, 90, 20, 40 }, temp;
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (a[i] < a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for (int i = 0; i < [Link]; i++) {
[Link](a[i]);
}
}
}
Console:
100
90
40
20
10
[Link] and Min number in given array:
---------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int a[] = { 10, 100, 90, 20, 40 }, temp;
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (a[i] < a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for (int i = 0; i < [Link]; i++) {
[Link](a[i]);
}
[Link]("Max no:" + a[0]);
[Link]("min no:" + a[[Link] - 1]);
}
}
Console:
100
90
40
20
10
Max no:100
min no:10
[Link] count:
-----------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome";
int vowelsCount = 0;
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' ||
ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I'
|| ch == 'O' || ch == 'U') {
vowelsCount++;
}
}
[Link](vowelsCount);
}
}
Console:
[Link] and vowels count:
-------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome";
int vowelsCount = 0;
int consonantCount = 0;
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' ||
ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I'
|| ch == 'O' || ch == 'U') {
vowelsCount++;
} else {
consonantCount++;
}
}
[Link](vowelsCount);
[Link](consonantCount);
}
}
Console:
3
4
[Link] the vowels and consonants seperately:
--------------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome";
String vowels = "";
String consonant = "";
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' ||
ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I'
|| ch == 'O' || ch == 'U') {
vowels = vowels +ch;
} else {
consonant=consonant+ch;
}
}
[Link](vowels);
[Link](consonant);
}
}
Console:
eoe
Wlcm
[Link] of each character in given String:
--------------------------------------------
package [Link];
import [Link];
import [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome";
Map<Character, Integer> emp = new LinkedHashMap<>();
char[] ch = [Link]();
for (char c : ch) {
if ([Link](c)) {
int count = [Link](c);
[Link](c, count + 1);
} else {
[Link](c, 1);
}
[Link](emp);
}
}
Console:
{W=1, e=2, l=1, c=1, o=1, m=1}
[Link] of the word in a given String:
------------------------------------------
package [Link];
import [Link];
import [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome to java sql java to java sql plsql";
String[] x = [Link](" ");
Map<String, Integer> emp = new LinkedHashMap<>();
for (String v : x) {
if ([Link](v)) {
int count = [Link](v);
[Link](v, count + 1);
} else {
[Link](v, 1);
}
}
[Link](emp);
}
}
Console:
{Welcome=1, to=2, java=3, sql=2, plsql=1}
[Link] the word count in given string:
---------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome to java sql java to java sql plsql";
String[] x = [Link](" ");
[Link]([Link]);
}
}
Console:
[Link] string into init cap:
------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome to java sql java to java sql plsql";
String[] x = [Link](" ");
String res = "";
for (String v : x) {
String first = [Link](0, 1);
String after = [Link](1);
res = res + [Link]() + after + " ";
}
[Link]([Link]());
}
}
Console:
Welcome To Java Sql Java To Java Sql Plsql
[Link] the count of caps,small,digit and sp count:
--------------------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "Welcome@123456";
int lcount = 0, dcount = 0, ucount = 0 , spcount = 0;
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if ([Link](ch)) {
ucount++;
} if ([Link](ch)) {
lcount++;
} if ([Link](ch)) {
dcount++;
} if
(&&) {
spcount++;
}
}
[Link]("Lowercase: "+lcount);
[Link]("Uppercase: "+ucount);
[Link]("Digit: "+dcount);
[Link]("Special Character: "+spcount);
}
}
Console:
Lowercase: 6
Uppercase: 1
Digit: 6
Special Character: 1
[Link] all Small case into caps and reverse:
------------------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
String name = "WelcomE";
StringBuffer b = new StringBuffer(name);
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if ([Link](ch)) {
[Link](i, [Link](ch));
} else {
[Link](i, [Link](ch));
}
}
[Link]([Link]());
Console:
wELCOMe
[Link] num or not:
-------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int n = 10;
int count = 0;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
count = 1;
break;
}
}
if (count == 0) {
[Link]("prime no");
} else {
[Link]("not a prime no");
}
}
console:
not prime
[Link] the prime no from 1 to 100:
---------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int count;
for (int n = 1; n <= 100; n++) {
count = 0;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
count = 1;
break;
}
}
if (count == 0) {
[Link](n);
}
}
}
}
Console:
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
[Link] number count from 1 to 500:
-------------------------------------
package [Link];
public class Employee {
public static void main(String[] args) {
int count;
int pCount = 0;
for (int n = 1; n <= 500; n++) {
count = 0;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
count = 1;
break;
}
}
if (count == 0) {
pCount++;
}
}
[Link](pCount);
}
}
Console:
96