SlideShare a Scribd company logo
1 of 28
Programming
Sample Input: Sample Output:
Found
Question 1
Write a Java code to search a given number in an array. If the element is
found then print Found, else print Not Found
arr_size = 5
arr[] = {23, 82, 57, 45, 38}
search_elem = 45
import java.util.Scanner;
public class MyClass {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int arr_size = sc.nextInt();
int arr[] = new int[arr_size];
int i;
for(i = 0; i < arr_size; i++)
{
arr[i] = sc.nextInt();
}
int search_elem = sc.nextInt();
int is_matched = 0;
for(i = 0; i < arr_size; i++)
{
if(arr[i] == search_elem)
{
is_matched = 1;
break;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if(is_matched == 1)
{
System.out.print("Found");
}
else
{
System.out.print("Not Found");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
2
Question 2
Write a Java code to find the number of occurrences of a given number in
an array.
arr_size = 6
arr[] = {3, 82, 57, 45, 3, 8}
search_elem = 3
import java.util.Scanner;
public class MyClass {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int arr_size = sc.nextInt();
int arr[] = new int[arr_size];
int i;
for(i = 0; i < arr_size; i++){
arr[i] = sc.nextInt();
}
int search_elem = sc.nextInt();
int count = 0;
for(i = 0; i < arr_size; i++)
{
if(arr[i] == search_elem)
{
count++;
}
}
System.out.print(count);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
7
Question 3
Write a Java code to find the largest number in an array.
arr_size = 5
arr[] = {1, 7, 3, 4, 5}
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int arr[]=new int[a];
for(int i = 0; i < a; i++)
{
arr[i] = sc.nextInt();
}
int max = 0;
for(int i = 0; i < a; i++)
{
if(arr[i] > max)
{
max = arr[i];
}
}
System.out.print(max);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
10, 20
30, 0
Question 4
Write a Java code to find all pairs of elements whose sum is equal to the
given value.
arr_size = 5
arr[] = {50, 10, 30, 20, 0}
value = 30
import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int arr[] = new int[a];
for(int i = 0; i < a; i++){
arr[i] = sc.nextInt();
}
int value = sc.nextInt();
int temp = 0;
for(int i = 0; i < a; i++) {
for(int j = i+1; j < a; j++) {
temp = arr[i]+arr[j];
if(temp == value){
System.out.print(arr[i]+ ", "+arr[j]);
System.out.println();
}
temp = 0;
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
3 4 5 1 2
Question 5
Write a Java code to rotate an array.
arr_size = 5
arr[] = {1, 2, 3, 4, 5}
no_of_rotations = 2
(HINT: You have to circularly left shift array by 2 positions)
import java.util.Scanner;
public class Main
{
public static void rotate_arr(int arr_size, int arr[], int no_of_rotate)
{
for(int i = 1; i <= no_of_rotate; i++)
{
int temp = arr[0];
for(int j = 1; j < arr_size; j++)
{
arr[j-1] = arr[j];
}
arr[arr_size-1] = temp;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int arr_size = sc.nextInt();
int arr[] = new int[arr_size];
for(int index = 0; index < arr_size; index++)
{
arr[index] = sc.nextInt();
}
int no_of_rotate = sc.nextInt();
rotate_arr(arr_size, arr, no_of_rotate);
for(int i = 0; i < arr_size; i++)
{
System.out.print(arr[i] + " ");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
1 7
Question 6
Write a Java code to find the unique element in the given array.
arr_size = 6
arr[] = {1, 2, 3, 2, 3, 7}
import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int arr_size = sc.nextInt();
int arr[] = new int[arr_size];
for(int index = 0; index < arr_size; index++)
{
arr[index] = sc.nextInt();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
for(int index1 = 0; index1 <= arr_size-1; index1++)
{
int has_occurred = 0;
for(int index2 = 0; index2 <= arr_size-1; index2++)
{
if((index1 != index2) && (arr[index1] == arr[index2]))
{
has_occurred = 1;
break;
}
}
if(has_occurred == 0)
{
System.out.print(arr[index1] + " ");
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
Yes
Question 7
Write a Java code to check whether the given array is a palindrome or not. If
the given array is a palindrome, then print "Yes". Otherwise, print "No".
arr_size = 5
arr[] = {4, 5, 3, 5, 4}
import java.util.Scanner;
class Main{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int arr_size = sc.nextInt();
int arr[] = new int[arr_size];
for(int idx = 0; idx <= arr_size - 1; idx++)
{
arr[idx] = sc.nextInt();
}
int left = 0;
int right = arr_size - 1;
boolean is_palindrome = true;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
while(left <= right)
{
if(arr[left] != arr[right])
{
is_palindrome = false;
break;
}
left++;
right--;
}
if(is_palindrome == true){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Predict the output
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int arr[] = {10, 20, 30, 40, 50};
System.out.print(arr[2]);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
MCQ
No output
Question 1
A)
ArrayIndexOutOfBoundsException
B)
40
C)
30
D)
// Predict the output
import java.util.Scanner;
class Main
{
public static void main (String[] args)
{
int arr[] = {10, 20, 30, 40};
int a = 50;
call(a,arr);
System.out.println(a);
System.out.println(arr[0]);
System.out.println(arr[1]);
}
public static void call(int a, int arr[])
{
a = a + 2;
arr[0] = 100;
arr[1] = 200;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
50
100
200
Question 2
A)
52
100
200
B)
50
10
20
C)
52
10
20
D)
// Predict the output
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Garbage value
Garbage value
Question 3
A)
ArrayIndexOutOfBoundsException
B)
Compilation error
C)
0
0
D)
THANK YOU

More Related Content

Similar to WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-1D_Program.pptx

QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory archana singh
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programsAbhishek Jena
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdfsowmya koneru
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...MaruMengesha
 
Demonstrating bully algorithm in java
Demonstrating bully algorithm in javaDemonstrating bully algorithm in java
Demonstrating bully algorithm in javaNagireddy Dwarampudi
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdfactocomputer
 
Code javascript
Code javascriptCode javascript
Code javascriptRay Ray
 

Similar to WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-1D_Program.pptx (20)

Java arrays
Java    arraysJava    arrays
Java arrays
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Insertion Sort Code
Insertion Sort CodeInsertion Sort Code
Insertion Sort Code
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
 
ISCP internal.pdf
ISCP internal.pdfISCP internal.pdf
ISCP internal.pdf
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Oot practical
Oot practicalOot practical
Oot practical
 
Demonstrating bully algorithm in java
Demonstrating bully algorithm in javaDemonstrating bully algorithm in java
Demonstrating bully algorithm in java
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
Code javascript
Code javascriptCode javascript
Code javascript
 
Programs of java
Programs of javaPrograms of java
Programs of java
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
Ann
AnnAnn
Ann
 

More from MaruMengesha

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...MaruMengesha
 
Chemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookChemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookMaruMengesha
 
eco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignmenteco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation AssignmentMaruMengesha
 
G12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookG12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookMaruMengesha
 

More from MaruMengesha (11)

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
 
Chemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookChemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text book
 
eco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignmenteco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignment
 
G12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookG12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text book
 

Recently uploaded

Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 

Recently uploaded (20)

Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-1D_Program.pptx

  • 1.
  • 3. Sample Input: Sample Output: Found Question 1 Write a Java code to search a given number in an array. If the element is found then print Found, else print Not Found arr_size = 5 arr[] = {23, 82, 57, 45, 38} search_elem = 45
  • 4. import java.util.Scanner; public class MyClass { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int arr_size = sc.nextInt(); int arr[] = new int[arr_size]; int i; for(i = 0; i < arr_size; i++) { arr[i] = sc.nextInt(); } int search_elem = sc.nextInt(); int is_matched = 0; for(i = 0; i < arr_size; i++) { if(arr[i] == search_elem) { is_matched = 1; break; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 5. if(is_matched == 1) { System.out.print("Found"); } else { System.out.print("Not Found"); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 6. Sample Input: Sample Output: 2 Question 2 Write a Java code to find the number of occurrences of a given number in an array. arr_size = 6 arr[] = {3, 82, 57, 45, 3, 8} search_elem = 3
  • 7. import java.util.Scanner; public class MyClass { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int arr_size = sc.nextInt(); int arr[] = new int[arr_size]; int i; for(i = 0; i < arr_size; i++){ arr[i] = sc.nextInt(); } int search_elem = sc.nextInt(); int count = 0; for(i = 0; i < arr_size; i++) { if(arr[i] == search_elem) { count++; } } System.out.print(count); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 8. Sample Input: Sample Output: 7 Question 3 Write a Java code to find the largest number in an array. arr_size = 5 arr[] = {1, 7, 3, 4, 5}
  • 9. import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int arr[]=new int[a]; for(int i = 0; i < a; i++) { arr[i] = sc.nextInt(); } int max = 0; for(int i = 0; i < a; i++) { if(arr[i] > max) { max = arr[i]; } } System.out.print(max); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 10. Sample Input: Sample Output: 10, 20 30, 0 Question 4 Write a Java code to find all pairs of elements whose sum is equal to the given value. arr_size = 5 arr[] = {50, 10, 30, 20, 0} value = 30
  • 11. import java.util.Scanner; public class Main{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int arr[] = new int[a]; for(int i = 0; i < a; i++){ arr[i] = sc.nextInt(); } int value = sc.nextInt(); int temp = 0; for(int i = 0; i < a; i++) { for(int j = i+1; j < a; j++) { temp = arr[i]+arr[j]; if(temp == value){ System.out.print(arr[i]+ ", "+arr[j]); System.out.println(); } temp = 0; } } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 12. Sample Input: Sample Output: 3 4 5 1 2 Question 5 Write a Java code to rotate an array. arr_size = 5 arr[] = {1, 2, 3, 4, 5} no_of_rotations = 2 (HINT: You have to circularly left shift array by 2 positions)
  • 13. import java.util.Scanner; public class Main { public static void rotate_arr(int arr_size, int arr[], int no_of_rotate) { for(int i = 1; i <= no_of_rotate; i++) { int temp = arr[0]; for(int j = 1; j < arr_size; j++) { arr[j-1] = arr[j]; } arr[arr_size-1] = temp; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 14. public static void main(String args[]) { Scanner sc = new Scanner(System.in); int arr_size = sc.nextInt(); int arr[] = new int[arr_size]; for(int index = 0; index < arr_size; index++) { arr[index] = sc.nextInt(); } int no_of_rotate = sc.nextInt(); rotate_arr(arr_size, arr, no_of_rotate); for(int i = 0; i < arr_size; i++) { System.out.print(arr[i] + " "); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 15. Sample Input: Sample Output: 1 7 Question 6 Write a Java code to find the unique element in the given array. arr_size = 6 arr[] = {1, 2, 3, 2, 3, 7}
  • 16. import java.util.Scanner; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int arr_size = sc.nextInt(); int arr[] = new int[arr_size]; for(int index = 0; index < arr_size; index++) { arr[index] = sc.nextInt(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 17. for(int index1 = 0; index1 <= arr_size-1; index1++) { int has_occurred = 0; for(int index2 = 0; index2 <= arr_size-1; index2++) { if((index1 != index2) && (arr[index1] == arr[index2])) { has_occurred = 1; break; } } if(has_occurred == 0) { System.out.print(arr[index1] + " "); } } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 18. Sample Input: Sample Output: Yes Question 7 Write a Java code to check whether the given array is a palindrome or not. If the given array is a palindrome, then print "Yes". Otherwise, print "No". arr_size = 5 arr[] = {4, 5, 3, 5, 4}
  • 19. import java.util.Scanner; class Main{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int arr_size = sc.nextInt(); int arr[] = new int[arr_size]; for(int idx = 0; idx <= arr_size - 1; idx++) { arr[idx] = sc.nextInt(); } int left = 0; int right = arr_size - 1; boolean is_palindrome = true; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 20. while(left <= right) { if(arr[left] != arr[right]) { is_palindrome = false; break; } left++; right--; } if(is_palindrome == true){ System.out.print("Yes"); } else{ System.out.print("No"); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 21. // Predict the output import java.util.Scanner; public class Main { public static void main(String args[]) { int arr[] = {10, 20, 30, 40, 50}; System.out.print(arr[2]); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 22. MCQ
  • 24. // Predict the output import java.util.Scanner; class Main { public static void main (String[] args) { int arr[] = {10, 20, 30, 40}; int a = 50; call(a,arr); System.out.println(a); System.out.println(arr[0]); System.out.println(arr[1]); } public static void call(int a, int arr[]) { a = a + 2; arr[0] = 100; arr[1] = 200; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 26. // Predict the output import java.util.Scanner; public class Main { public static void main(String args[]) { int arr[2]; System.out.println(arr[0]); System.out.println(arr[1]); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 27. Garbage value Garbage value Question 3 A) ArrayIndexOutOfBoundsException B) Compilation error C) 0 0 D)

Editor's Notes

  1. 1st slide (Mandatory)
  2. Section End/Start Use this at section’s start or end. For example: “Questions” or “Time for Practice”. To be used for Impacts (get the student’s attention).
  3. Input : arr_size = 6 arr[] = {23, 82, 57, 45, 38, 63} search_elem = 12 Output: Not Found
  4. Question+ Input + Output (Programming)
  5. Question+ Input + Output (Programming)
  6. Question+ Input + Output (Programming)
  7. Output: 4 7 34 67 100
  8. Output: 4 7 34 67 100
  9. Section End/Start Use this at section’s start or end. For example: “Questions” or “Time for Practice”. To be used for Impacts (get the student’s attention).
  10. We have passed the variable 'a' and array values to the function. Inside the function, value 2 is added with the variable 'a' and array values in the index 0 and 1 are changed with different values. The added value is not printed inside the main function. This is because 'a' is a single variable. But for an array, when we try to print inside the main function the values get changed. This is because while passing an array it's reference will be passed.
  11. Thank you slide