Missing Attendance roll number: Given roll numbers from 1 to N,one is missing. Find the missing number
int rolls[]={1,2,3,5}
output: Missing number=4
——————————————————————————
2)Find Duplicate ID: In an employee array, one ID is duplicated. Find that duplicate
int empIDs={101, 103, 104, 101, 105}
output: Duplicate: 101
class DuplicateID
{
public static void main(String args[])
{
int arr[]={101, 103, 104, 101, 105};
for(int i=0; i<arr.length; i++)//0<5
{
for(int j=i+1; j<arr.length; j++)//3<5
{
if(arr[i]==arr[j])//101==101
{
System.out.println(“Duplicate ID is=” +arr[i]);//101
break;
}
}
}
——————————————————————————
3)Employee Overtime Tracker: If hours worked > 8, print name and hours
String names[]={“john”, “Abi”, “Arron”};
int hours[]={7, 10, 9}
output: Abi: 10
Arron: 9
class OvertimeTracker
{
public static void main(String args[])
{
String names[]={“john”,”Abi”,”Arron”};
int hours[]={7,10,9};
for(int i=0; i<hours.length; i++)//2<3
{
if(hours[i] >8)9>8
{
System.out.println(names[i]+”:”+hours[i]);//Abi:10 Arron:9
}
}
}}
——————————————————————————
4)Machine Temperature Spike: If temperature > 100, then mark it as “overheated”
int temp[]={95, 102, 99, 108}
output: sensor 2: Overheated
sensor 4: Overheated
class Check
{
public static void main(String args[])
{
int temp[]={95, 102, 99, 108};
for(int i=0; i<temp.length; i++)//3<4
{
if(temp[i] >100)//108>100
{
System.out.println(“sensor “+”i+1″+”overheated”);//sensor 2: overheated
sensor 4: overheated
}
}
}}