Java DSA Kunal Kushwaha
Java DSA Kunal Kushwaha
Assize
Max
10/4
=
A =
"
b =
20
isffb > max :
C =
30 b
Max =
if e > max :
max =
8
④
0 1st
i s 4 S
6 7
ii.
%%!I:÷
,
. -
2 '
.
.
'
3 .
%5
?⃝
n =
13 -85705708079 A
13890/10 h % to
lastdigit
=
n =
10313897138
-1380¥
N __
13839 ¥2 13839 %w=q
I
count -0
138 =3
? 1-
while # e) {
Krem
✗ last digit
-
1,38--8
n -1.10
3) 2 v
iyfrem
__ =
13
=
3
wwrttti
It
v
}
/
1 -
Ho _③
n=n
j
' •
M
3 ✓ ① As
0
.
Q . h= 23597
Ay79S3①
|
②
" " " + " "
"
"
=
79×-101-5--795
= 795*10 -13--7953
= 7953×-10+2
-_79s①⑥
1
System.out.println(salary);
}
}
Output :- 27400
}
}
Output :- 28400
int max = a;
if(b>max){
max = b;
}
if (c > max){
max = c;
}
System.out.println(max);
}
}
# Approach – 2:-
import java.util.Scanner;
public class LrgestOfThree {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int max = 0;
if(a > b){
max = a;
} else {
max = b;
}
if (c > max){
max = c;
}
System.out.println(max);
}
}
# Approach 3 :-
Using Math.max :- Math is a class present in java.lang package and max is a
function present in it which takes two number as an argument and return maximum
out of them.
import java.util.Scanner;
public class LrgestOfThree {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
Counting occurrence :-
“ Input two numbers, find that hoe many times second number
digit is present in first number”
Ex :- first number = 14458
Second number = 4
Output = 2, because 4 is present 2 times in first number.
import java.util.Scanner;
Reverse a number
“ A number I input from the keyboard and Show the output as
Reverse of that number “
Example :- Input :- 12345
Output :- 54321
import java.util.Scanner;
public class ReverseANumber {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
int ans = 0;
while(num > 0){
int rem = num % 10;
num /= 10;
ans = ans * 10 + rem;
}
System.out.println(ans);
}
}
Input :- 458792
Output :- 297854
Calculator Program
import java.util.Scanner;
if (op == '+') {
ans = num1 + num2;
}
if (op == '-') {
ans = num1 - num2;
}
if (op == '*') {
ans = num1 * num2;
}
if (op == '/') {
if (num2 != 0) {
ans = num1 / num2;
}
}
if (op == '%') {
ans = num1 % num2;
}
} else if (op == 'x' || op == 'X') {
break;
} else {
System.out.println("Invalid operation!!");
}
System.out.println(ans);
}
}
}