Professional Documents
Culture Documents
19BIT0113
JAVA LAB FAT
QUES 2
Write a java code to count and show the Magic numbers of given array of integer numbers
(i) Sort(ascending) the given array by ignoring the numbers which contains zero’s(Ex: 12030
(ii) Sort(ascending) the given array after remove the odd digits in each items. If number
contains more than two digits, then only remove odd digits otherwise ignore that particular
number(Ex1- 1235867 - after removed odd digits from 1235867 you will get 256. Ex2- 33 no
m
er as
need to remove any digits from this number) [25 Mark]
co
Magic Number: If any index item has not changed its original inputted index item after
eH w
o.
performed (i) and (ii) operation. rs e
Note: Implement the above operations using package concepts. [5 Mark]
ou urc
Final Output:
FUNCTIONS FOR
ed d
PACKAGE JAVA3
is
package java3;
import java.util.*;
Th
int temp = 0;
sh
This study source was downloaded by 100000805033309 from CourseHero.com on 06-02-2021 23:43:17 GMT -05:00
https://www.coursehero.com/file/84129912/19BIT0113-VL2020210103971-FATpdf/
System.out.println();
OUTPUT
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
CODE
package java3;
ed d
import java.util.*;
ar stu
int power = 0;
Th
while (n>0)
{
digit =(int) n%10;
if (digit %2 == 0)// if digit is odd
{
sh
This study source was downloaded by 100000805033309 from CourseHero.com on 06-02-2021 23:43:17 GMT -05:00
https://www.coursehero.com/file/84129912/19BIT0113-VL2020210103971-FATpdf/
x.odd(123);
}
}
OUTPUT
m
package java3;
er as
import java.util.*;
public class zero {
co
public void ignore0(int [] arr) {
eH w
o.
int digit,j=0; rs e
for(int i =0;i<arr.length;i++) {
while(arr[i]>0) {
ou urc
digit = arr[i]%10;
if(digit==0) {
continue;
o
}
aC s
else {
vi y re
arr[j]=arr[i];
}
}
}
ed d
}
is
FINAL CODE
Th
PACKAGE JAVA_DA
CODE
sh
package java_da;
import java.io.*;
import java3.sorting;
import java3.odd_digits;
import java3.zero;
This study source was downloaded by 100000805033309 from CourseHero.com on 06-02-2021 23:43:17 GMT -05:00
https://www.coursehero.com/file/84129912/19BIT0113-VL2020210103971-FATpdf/
int [] a = {1,4,5,45,2,20};
int j=0;
for(int i =0;i<a.length;i++) {
odd_digits x = new odd_digits();
int y=x.odd(a[i]);
a[j]=y;
}
sorting b = new sorting();
b.ascending(a);
zero c = new zero();
c.ignore0(a);
}
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh
This study source was downloaded by 100000805033309 from CourseHero.com on 06-02-2021 23:43:17 GMT -05:00
https://www.coursehero.com/file/84129912/19BIT0113-VL2020210103971-FATpdf/
Powered by TCPDF (www.tcpdf.org)