Professional Documents
Culture Documents
Output:
Q1. (b)
Code:
import java.util.Scanner;
Output:
Q1. (c)
Code:
import java.util.Scanner;
Output:
Q2.
Code
import java.sql.SQLOutput;
import java.util.Scanner;
Output:
Q3.
Code
import java.util.Scanner;
public class marks {
public static void main(String args[]){
int math, physics, chem, eng, cs;
Scanner sc = new Scanner(System.in);
System.out.println("Enter math marks: ");
math = sc.nextInt();
System.out.println("Enter physics marks: ");
physics = sc.nextInt();
System.out.println("Enter chemistry marks: ");
chem = sc.nextInt();
System.out.println("Enter english marks: ");
eng = sc.nextInt();
System.out.println("Enter computer science marks: ");
cs = sc.nextInt();
float overall_avg = (math+physics+chem+eng+cs)/5;
float eng_av = (math*math)+physics+(chem/4);
float csa = cs;
Output:
Q6.
Code
import java.util.Scanner;
Q7.
Code:
import java.util.Scanner;
Output:
Q8.
Code:
import java.util.Scanner;
public class matrix_addition {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
int m = sc.nextInt();
System.out.println("Enter the number of columns: ");
int n = sc.nextInt();
int a[][] = new int[m][n];
int b[][] = new int[m][n];
int c[][] = new int[m][n];
System.out.println("Enter elements for matrix A ");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
a[i][j] = sc.nextInt();
}
}
System.out.println("Enter elements for matrix B ");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
b[i][j] = sc.nextInt();
}
}
System.out.println("Matrix A: ");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("Matrix B: ");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(b[i][j]+" ");
}
System.out.println();
}
System.out.println("The addition of the matrices give us: ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j] = a[i][j]+b[i][j];
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}}
Output: