EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

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

}

}

}}

Java example programs for practicing

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer