Java program 1: click here
Java program 2: click here
Java program 3: click here
Java program 4: click here
Java program 5: click here
Java program 6: 👇👇👇👇👇👇
1. Write a program to read integer value and display sum of all even and odd numbers (using array)
import java.util.Scanner;
public class EvenOddSum {
public static void main(String[] args) {
int i,esum=0,osum=0;
System.out.println("enter size of array");
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();
System.out.println("Enter "+s+" element of array");
int arr[]=new int[s];
for( i=0;i<s;i++)
{
arr[i]=sc.nextInt();
if(arr[i]%2==0)
esum=esum+arr[i];
else
osum=osum+arr[i];
}
System.out.println("Sum of Even numbers: "+esum+"\nSum of odd numbers: "+osum);
}
}
Don't write this one it is for understanding purpose only 👇👇👇
esum-----> Even sum
osum-----> Odd sum
s-----------> size of array
arr--------> array name
2. Write a program to perform linear search on a given number
import java.util.Scanner;
public class LinearSearch {
public static void main(String[] args) {
int i,flag=0,arr1[];
System.out.println("enter size of array");
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();
System.out.println("Enter "+s+" element of array ");
arr1=new int[s];
for( i=0;i<s;i++)
arr1[i]=sc.nextInt();
System.out.println("enter element to search:");
int sah=sc.nextInt();
for(i=0;i<s;i++)
if(arr1[i]==sah)
{
flag =1;
break;
}
if(flag==1){
System.out.println("element found at index:"+i);
System.out.println(i+1);}
else
System.out.println("element not found");
}
}
Don't write this one it is for understanding purpose only 👇👇👇
arr1-------++> Array name
s-----------++-->Size
i-------------++--> for repetation
sah----+--+-----> Search
3. Write a program to find sum of 2 Matrix
import java.util.*;
public class MatrixSum {
public static void main(String[] args) {
int i,j,a[][],b[][];
Scanner sc=new Scanner(System.in);
System.out.println("Enter size1 & size2:");
int s1=sc.nextInt();
int s2=sc.nextInt();
System.out.println("Enter "+s1*s2+" element of 1st array: ");
a=new int [s1][s2];
for(i=0;i<s1;i++)
{
for(j=0;j<s2;j++)
{
a[i][j]=sc.nextInt();
}}
System.out.println("Enter "+s1*s2+" of 2nd array");
b=new int [s1][s2];
for(i=0;i<s1;i++){
for(j=0;j<s2;j++){
b[i][j]=sc.nextInt();
}}
System.out.println("Sum of 2 matrix is:");
for(i=0;i<s1;i++){
for(j=0;j<s2;j++){
System.out.print(a[i][j]+b[i][j]+"\t");
}
System.out.println();
}
}
}
Don't write this one it is for understanding purpose only 👇👇👇
i,j--------> for repetation
a[]--++---> first array
b[]---++---> Second Array
s1--++------> Size of Array
s2--++------> Size of Array
I am not responsible if any thing goes wrong due to this post
If anyone didn't understood these programs just feel free to call
1 Comments
Wow thanks for helping me
ReplyDelete