====PROBLEM’s====
Index
S. No. Title Pages
1. (Q24) Arithmetic Operation 1-5
2. (Q5) Arithmetic Assignment Operator 6
3. (Q8) Relational Operator 7-8
4. (Q9) Logical Operator 9-10
5. (16) Increment & Decrement Operator 8-13
6. (32) Condition Operator 14-17
7. (Q10) if else 18
8. (Q14) While Loop – I 19-20
9. (Q23) While Loop – II 20-22
10. (Q42) While Loop – III 23-32
11. (Q5) Do-While Loop 33
1
1-: Arithmetic Operator :-(1-2)
Q1: For a given number int n=5783;
a. Print the last digit AND last two digit of the number
[Link](n%10);
[Link](n%100);
b. Remove the last digit AND last two digit of the number
[Link](n/10);
[Link](n/100);
Q2: For a given number int n=5783;
Print each digit of the number one by one from Right to Left.
Q3: For a given number int n=5783;
Print each digit of the number one by one from Left to Right.
1
Q4: WAJP to swap two numbers.
a. With using a third variable
b. Without using third variable
Q5: For the given three numbers. Swap 1st into 2nd , 2nd into 3rd and
3rd into 1st number.
a. With using fourth variable
b. Without using fourth variable
2
Q6: For the given CP and SP. Calculate %Profit.
CP=120; SP=160;
Q7: For the given CP and SP. Calculate %Loss.
CP=120; SP=90;
Q8: Find the Last Digit of a Number Without using % operator.
Q9: Reverse a 3-Digit Number Using Pure Arithmetic operator.
Q10: Find Sum of three Digit number Without using Loops
3
Q11: Find Sum of First N Natural Numbers Without Loop
Q12 Find Sum of all odd Numbers up to n Without Loop
Q13: Find Sum of all even Numbers up to n Without Loop
Q14. Find Sum of squares of all Numbers up to n Without Loop
4
Q15: Evaluate the Expression:
int x = 5 / 2 * 2;
[Link](x);
Q16: valuate the Expression:
int n = 128;
int rev = (n % 10) * 100 + ((n / 10) % 10) * 10 + (n / 100);
[Link](rev); //821
Q17: Evaluate the Expression:
int n = 120;
int rev = (n % 10) * 100 + ((n / 10) % 10) * 10 + (n / 100);
[Link](rev); //21
Q18: Evaluate the Expression:
int x = 1 + 2 * 3 / 4;
[Link](x); //2
Q19: Evaluate the Expression:
int x = 1 + 2 / 3 * 4;
[Link](x); //1
Q20: Evaluate the Expression:
int x = 100 / 10 * 2 % 3;
[Link](x); //2
Q21: [Link](0/0); //ArithmeticException
Q22: [Link](0.0/0.0); // NaN
Q23: [Link](1.0/0.0); // Infinity
Q24: [Link](-1.0/0.0); // -Infinity
5
2-: Arithmetic Assignment Operator (6)
Q1. Evaluate the expression:
Int a=8, b=4, c=2;
a+=(a+b-c)/2;
[Link](a); // 13
Q2. Evaluate the expression:
Int n=436;
n/=10;
[Link](n); // 43
Q3. Evaluate the expression:
Int n = 436;
n %= 10;
[Link](n); // 6
Q4. Evaluate the expression:
int num = 7;
num /= 2;
[Link](num); // 3
Q5. Evaluate the expression:
Int n=36;
n*=2;
n*=2;
[Link](n); // 144
6
3-: RELATIONAL Operator :-( 7-8 )
Q1. Evaluate the expression:
int x = 5, y = 10;
[Link](x == y == false); // T
Q2. Evaluate the expression:
int x=64, y=20;
[Link](x+y>3*y); // T
[Link]((x+y)/12==0); // F
[Link]((x+y)/12!=0); // T
[Link]((x+y)/12==7); // T
[Link]((x+y)/12!=7); // F
Q3. Evaluate the expression:
int x=64, y=20, z=1900;
[Link]((x+y)%12==0); // T
[Link]((x+y)%12!=0); // F
[Link](z%100!=0); // F
Q4. Evaluate the expression:
double d = 0.0/0.0;
[Link](d == d); // F
[Link](d != d); // T
[Link](d < d); // F
7
[Link](d > d); // F
[Link](d <= d); // F
Q5. Evaluate the expression:
int x = 5;
[Link](1 < x < 10); // Compilation error
Q6. Evaluate the expression:
char c1 = 'A';
char c2 = 65;
[Link](c1 == c2); // T
[Link](c1 < 'a'); // T
[Link]('Z' < 'a'); // T
Q7. Evaluate the expression:
boolean p = true;
boolean q = false;
[Link](p == q == false); // T
Q8. Evaluate the expression:
int p = 3, q = 5;
[Link]((p += 2) > (q -= 2)); // T
[Link](p + " " + q); // 5 3
8
4-: LOGICAL Operator :-(9-10)
Q1.
boolean a=true;
boolean b=false;
boolean c=true;
boolean result=(a && b) || (b && c);
[Link](result); // F
Q2.
int x=5;
int y=10;
boolean result=(++x > 5) && (--y < 10);
[Link](result); // T
[Link](x+y); // 15
Q3.
int x=5;
int y=10;
boolean result=(x++ > 5) && (--y < 10);
[Link](result); // F
[Link](x+y); // 16
Q4. boolean a=true;
boolean b=false;
boolean c=true;
boolean result=(a || b) && (b || c);
[Link](result); // T
9
Q5.
int a=20;
int b=30;
[Link](a++>15 && b++>20); // T
[Link](a+b); // 52
Q6.
int a=20;
int b=30;
[Link](a++>25 && b++>20); // F
[Link](a+b); // 51
Q7.
int a=20;
int b=30;
[Link](a++>25 || b++>20); // T
[Link](a+b); // 52
Q8.
int a=20;
int b=30;
[Link](a++>15 || b++>20); // T
[Link] a given year print true if it is a leap year or print false if
it is not a leap year.
[Link]
function/problem
10
5-: INCREAMENT & DECREAMENT Operator :- (8-13)
Solve and Answer:-
Q1:
int a=10; int b=a++;
[Link](a); // 11
[Link](b); // 10
Q2: Solve and answer value of a, b and c.
int a=20;
a++;
int b=a++;
int c=++b;
[Link](a); // 22
[Link](b); // 22
[Link](c); // 22
Q3: Solve and answer value of a, b and c.
int a=12;
int b=a++;
11
b++;
int c=a++ + --b;
[Link](a); // 14
[Link](b); // 12
[Link](c); // 25
Q4: Solve and answer value of a, b and c.
int a=10;
a++;
int b=++a;
int c=a++ + ++b;
b++;
[Link](a); // 13
[Link](b); // 14
[Link](c); // 25
Q5: Solve and answer value of c.
int a=12;
int b=20;
int c= a++ +b++ - ++a- --a;
[Link](c); // 5
12
Q6: Solve and answer value of z.
int x=10;
int y=5;
int z=x-- - --y + x++ + ++y;
[Link](z); // 20
Q7: Solve and answer value of result.
int x = 5;
int result = x++ - --x + x-- - --x;
[Link](result); // 2
Q8: Solve and answer value of c.
int a=5;
int b=10;
int c=a-- + ++b - b-- + ++a;
[Link]( c ); // 10
Q9: Solve and answer value of x.
int x=12;
x=x++;
13
x=x++;
x=x++;
x=++x;
x=x++;
[Link](x); // 13
Q10: Solve and answer value of x, y, z and p.
int x=12;
int y=x++ + ++x;
y++;
int z=++y;
int p=x++ - ++y + z++;
[Link](x); // 15
[Link](y); // 29
[Link](z); // 29
[Link](p); // 13
Q11: Solve and answer value of a, b and c and d.
int a=12;
int b=a++;
b++;
14
int c=a++ + --b;
int d=a++ + ++b + c++;
d++;
c--;
[Link](a);// 15 [Link](b); //13
[Link](c);//25 [Link](d); //53
Q12: Solve and answer value of a, b and c and d.
int a=12;
a++;
++a;
int b=a++;
b++;
int c=a++ + --b;
c--;
--b;
int d=++a + b++ + --c;
[Link](a); //17
[Link](b); //14
[Link](c); //27
[Link](d); //57
15
Q13:
int a=8;
int b=12;
int c= ++a +b++;
c--;
--b;
int d= c-- + ++b + ++a;
int e= a + ++b +c + d++;
[Link] (++e); // 87
Q14:
int x = 4, y = 6;
x += (y++ * 2);
[Link](x + " " + y); // 16 7
Q15:
int p = 5, q = 2;
p *= ++q + p++;
[Link](p + " " + q); // 40 3
16
(6)-: CONDITION Operator :-(14-17)
Q1: What is the output of the program:
int a = 3, b = 4, c = 5;
int result = (a > b) ? (a > c ? a : c) : (b > c ? b : c);
[Link](result); // 5
Q2: What is the output of the program:
int x = 10; int y = 5;
int z = (x > y) ? (x < 15 ? x : y) : (x > 5 ? y : x);
[Link](z); // 10
Q3: What is the output of the below program?
int x = 10; int y = 5; int z = 7;
int result = (x < y) ? (y < z ? z : y) : x;
[Link](result); // 10
Q4: What is the output of the below program?
int a = 1, b = 2, c = 3;
int result = a < b ? a < c ? c : a : b;
[Link](result); // 3
Q5: What is the output of the below program?
int a = 5; int b = 10;
int c=(a>b) ? b++ : (a<b ? --b : b) ;
[Link](c); // 9
17
Q6: What is the output of the below program?
int val=10;
int result=(value>5) ? (value<8?1:2) : 3;
[Link](result); //Compilation error
Q7: What is the output of the below program?
int x=5, y=7, z=3;
int result=(x>y) ? (x>z? x:z) : (y>z ? y:z);
[Link](result); // 7
Q8: What is the output of the below program?
int x=5, y=7, z=3;
int result=(x<y) ? (x<z? x:z) : (y<z ? y:z);
[Link](result); // 3
Q9: WAJP to check and print the given number is an even number or not.
Q10: WAJP to check and print the given +ve number is a three digit
number or not.
18
Q11: WAJP to check and print the given number is divisible by both 3
and 5 or only by 3, only by 5 or None.
Q12: For given numbers x and y. check whether
y is a factor of x or not.
Input: x=12, y=4
Output: x is a factor of y
Q13: WAJP to check whether the three sides of a triangle is valid or not.
19
Q14: Given a character, check if it's uppercase,lowercase, digit or
special character.
Q15: int a = 5, b = 10;
int c = (a > b) ? a++ : b++;
[Link](a + " " + b + " " + c); // 5 11 10
Q16: WAJP to print the bigger of two numbers.
Q17: WAJP to print the smaller of two numbers.
Q18: WAJP to print the biggest of three numbers.
Q19: WAJP to print the smallest of three numbers.
20
Q20WAJP to print the biggest of four numbers.
Q21: WAJP to print the smallest of four numbers.
Q22: Print if a year is a leap year or NOT using only conditional operator.
Q23: Test the Rank of a student
int marks = 72;
Output: ["Distinction" (>=75)], "First Class"
(>=60), "Second Class" (>=50),
“Pass“ (>=35), “Fail”
21
Q24: Given three numbers, print them in
sorted order (ascending)
int a = 9, b = 2, c = 7;
// Output: 2 7 9
Q25: Return second largest of three distinct numbers using ternary
operator only.
__LeetCode__
Q26: Bulb Game
22
Q27: Divisor Game
Return n%2 == 0
Q28: Nim Switcher
Q29: Statement: There are n coins. Each turn you can take 1 or
2coins. What is the logic that the first person will win?
n 2p
1 → A
2 → A
3 → K
4 → A n%3 != 0;
5 → A
6 → K
23
(7) if else (18)
Q1: WAJP to print big of two numbers using if else statement.
Q2: WAJP to print all are equal if all have same value or print biggest of
three numbers using if else statement.
Q3: WAJP to take a character input and print it is alphabet or not using
if else statement.
Q4: WAJP to take a character input and print it is upper case, lower
case or other alphabet using if else statement.
Q5: WAJP to take a character input and print it is an upper case
alphabet, lower case alphabet, a digit or a special character using if else
statement.
Q6: WAJP to take three angles of a triangle from user and print triangle
is valid or not using if else statement.
Q7: WAJP to take three sides of a triangle and print it is a valid triangle
or not using if else statement.
Q8: WAJP to take three sides of a triangle and print it is equilateral,
isosceles or scalene triangle or not using if else statement.
Q9:WAJP to take year input from user and print it is a Leap year or NOT.
Q10: WAJP to take CP and SP from user and print %Profit or % Loss in
the transaction.
24
(8) While Loop - I (19-20)
Q1: WAJP to print all the numbers from 1 to 10.
Q2: WAJP to print all the numbers from 10 to 1.
Q3: WAJP to print all the odd numbers from 1 to 100.
Q4: WAJP to print and count all the numbers from 1 to 100 which are
divisible by 7.
Q5: WAJP to print and count all the numbers from 1 to 100
Q7: WAJP to print and count all the numbers from 1 to 1000 which
are divisible by 7 and also ends with 7.
Q8: WAJP to print all the factors of a number
i/p: 28
o/p: 1 2 4 7 14
Q9: WAJP to count the factors of a number.(number itself excluded)
i/p: 28
o/p: Total Factors are: 5
Q10: WAJP to print and count all the factors of a number.(number
itself excluded)
i/p: 28
o/p: 1 2 4 7 14
Total Factors are: 5
25
Q11: WAJP to print a number is prime number or not.
Q12: WAJP to print all the terms of Fibonacci series up to n
i/p: 7
o/p: 0 1 1 2 3 5 8 13
Q13: WAJP to print the nth term of Fibonacci series
i/p: 7
o/p: 13
Q14: Nth Term of Fibonacci:
[Link]
(9) While Loop – II (20-22)
1) WAJP to print sum of all natural numbers from 1 to 100.
1+2+3+4+.........+100
2) WAJP to print sum of all even numbers from 1 to 100.
2+4+6+8+.........upto 100
3) WAJP to print sum of squares of all natural numbers from 1 to
100. 1+3+5+7+………….upto 100
4) WAJP to print sum of squares of all natural numbers from 1 to
100.
26
5) WAJP to print sum of cubes of all natural numbers from 1 to 100.
6) WAJP to print sum of squares of all even numbers from 1 to 100.
7) WAJP to print sum of cubes of all even numbers from 1 to 100.
8) WAJP to print sum of squares of all odd numbers from 1 to 100.
9) WAJP to print sum of cubes of all odd numbers from 1 to 100.
10) WAJP to print the sum of below series:
1 ∗ 2 + 2 ∗ 3 + 3 ∗ 4 ... ... upto 100
11) WAJP to print the sum of below series:
1*22+2*32+3*42…………upto 100
12) WAJP to print the sum of below series:
12+2+22*3+32*4………..upto 100
13) WAJP to print the sum of below series:
14) WAJP to print the sum of below series:
1/2+1/4+1/6+1/8……….100
15) WAJP to print the sum of below series:
1/1+1/3+1/5+1/7………….100
16) WAJP to print the sum of below series:
1/12+1/22+1/32+1/42……………..100
17) WAJP to print the sum of below series:
1/13+2/23+1/33+1/43………………100
27
18) WAJP to print the sum of below series
19) WAJP to accept a input from user and print factorial of that
number.
i/p: 6
o/p: 6!= 720
20) WAJP to accept 2 numbers from user and print power of a to b.
i/p: 6 3
o/p: 6 to power 3 is: 216
21) WAJP to accept a number from user andprint sum of all its
factors(number itself excluded).
i/p: 14
o/p: sum is: 10 (1+2+7)
22) WAJP to accept a number from user and print the number is a
perfect number or not.
i/p: 28
o/p: 28 is a perfect number
Perfect number: if the sum of all factors of a
Number is equals to number itself then
It is a perfect number.
23) Perfect Number: ON LEET
28
(9) While Loop – III (23-32)
1) . Write a java program to take a user input and print each
digits of the number one by one from right to left.
Input:
N=43705;
Output:
5
0
7
3
4
2). Write a java program to take a user input
and print each even digits of the number
one by one.
Input:
N=43705;
Output:
0
4
29
3). Write a java program to take a user input
and print each odd digits of the number
one by one.
Input:
N=43705;
Output:
5
7
3
4). Write a java program to take a user input and print each
digits of the number which are greater than or equals to 5
one by one.
Input:
N=43705;
Output:
5
7
5). Write a java program to take a user input and print the
biggest digit of the number.
Input:
N=43705;
Output: 7
30
6). Write a java program to take a user input and print the
difference of biggest digit and smallest digit of the number.
Input:
N=42375;
Output: 5
7). Write a java program to take a user input and count the
total digit of the number.
Input:
N=43705;
Output: 5
8). Write a java program to take a user input and print
each digit of the number from left to right.
Input:
N=43705;
Output:
4
3
7
0
5
31
9). Write a java program to take a user input and print each
digit of the number from left to right(Without using any
inbuilt
features)
Input:
N=43705;
Output:
4
3
7
0
10). Write a java program to take a user input and count
how many 0 digit is in number.
Input:
N=430705;
Output: 2
11). Write a java program to take a user input and count
how many 3 has appeared in the number
Input:
N=4373533;
Output: 4
32
12). Write a java program to take a user input and count
the even digits of the number.
Input:
N=42765;
Output: 3
13). Write a java program to take a user input and count
the odd digits of the number.
Input:
N=42765;
Output: 2
14). Write a java program to take a user input and count all
the digits of the number which are less than or equals to 5.
Input:
N=42765;
Output: 3
15). Write a java program to take a user input and print the
sum of each digit of the number.
Input:
N=4207065;
Output: 24
33
16). Write a java program to take a user input and print the
sum of each even digits of the number.
Input:
N=42765;
Output: 12
17). Write a java program to take a user input and print the
sum of each odd digits of the number.
Input:
N=42763;
Output: 10
18). Write a java program to take a user input and print the
sum of each digits of the number which are less than or
equals to 5.
Input:
N=42765;
Output: 11
19). Write a java program to take a user input and print the
product of each digit of the will be even or Odd.
Input:
34
N=9735;
Output: It will give Odd Product
20). Product and Sum Difference:
[Link]
sum-of-digits-of-an-integer/description/
21). Design a method which will accept a number and will
return true if all the digits of the number is in increasing
order.
Input:
N=2568;
Output: true
22). Design a method which will accept a number and will
return true if all the digits of the number is in decreasing
order.
Input:
N=7652;
Output: true
23). Design a method which will accept a number and will
return true if it has different adjacent digits.
Input:
N=726352;
Output:
true
35
24). Add Digit:
[Link]
25). Count Digits that divides Number:
[Link]
divide-a-number/description/
26). Write a java program to take a user input and print the
factorial of each digits of the number.
Input:
N=42065;
Output:
5!=120
6!=720
0!=1
2!=2
4!=24
27). Write a java program to take a user input and print the
sum of factorial of each digits of the number.
Input:
N=42065;
Output: 867 (120+720+1+2+24)
36
28). Write a java program to take a user input and print
whether the number is a strong number or not.
Input:
N=145;
Output: 145 is a Strong Number.
Strong number:
If the sum of factorials of each digit of a number is equal to
number itself then it is a Strong number.
Eg:
N= 145
Factorial sum=1!+4!+5!= 1+24+120= 145 which is equal to
number itself
29). Write a java program to take a user input and reverse
the number.
Input:
N=3745; Output: 5473
30). Write a java program to take a user input and print
whether the number is a palindrome number or not.
Palindrome Number: if number and its reverse is same then
it is called palindrome number.
Input:
N=34843
Output:
34843 is a Palindrome Number
37
31). Palindrome Number:
[Link]
32). Write a java program to take a String input and
check whether the given String is a palindrome
String or not.
33). WAJP to take user input and count the number of
binary bits in that number when it is represented in binary
form.
n=20 {binary=10100}
o/p : 5
34). Number of 1 Bits:
35). WAJP to take user input and count the number of 0’s
bits and 1’s bits in that number.
36). Binary Number with Alternating Bits
37). Number of Steps to Reduce a Number to Zero
38). Factorial Trailing Zeroes
39). Alternating Digit Sum:
40). Power of Two or NOT
41). Power of Three or NOT:
42). Power of Four or NOT:
38
(10) Do-While Loop (33)
Q1). WAJP to print factorial and ask user in end to press Y/n
to continue or any other key to exit.
Q2). WAJP to print power of a and b and ask user in end to
press Y/y to continue or any other key to exit.
Q3). WAJP to check a number is a prime number or not and
ask user in end to press Y/y to continue or any other key to
exit.
Q4). WAJP to keep taking input from the user until
they enter a negative number. When –ve
number or zero is entered then print sum of all
the +ve number entered.
Q5). Simple Password Validation System:
Create a login simulation where the user has
maximum 3 attempts to enter the correct password. If
the password is correct, print Login Successful. If all 3
attempts are used and the password is incorrect, print
Account Locked.
39