Assignment No - 07

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

JAVA ASSIGNMENT ROLL 05 20.12.

2010

ASSIGNMENT NO . 07

//Sumof series

import java.util.*;

class SumSer{
Scanner sc=new Scanner(System.in);
int s,n;
void getData(){
System.out.println("Enter the range of the no.....");
n=sc.nextInt();
}
void sum(){
for(int i=1;i<=n;i++){
s=s+i;
}
System.out.println("Result="+s);
}
}

class Ass3{
public static void main(String[] args){
SumSer s=new SumSer();
s.getData();
s.sum();
}
}
JAVA ASSIGNMENT ROLL 05 20.12.2010

ASSIGNMENT NO . 08

import java.util.*;

class StringOperation {

Scanner sc=new Scanner(System.in);

String st;

void getString() {

System.out.println("Enter a string...");

st=sc.nextLine();

void reverse() {

System.out.println("-----------------------------------");

System.out.println(st);

System.out.println("-----------------------------------");

for(int i=st.length()-1;i>=0;i--) {

System.out.print(st.charAt(i));

void wordCount() {

System.out.println("-----------------------------------");

System.out.println(st);

System.out.println("-----------------------------------");
JAVA ASSIGNMENT ROLL 05 20.12.2010

int c = 0;

for(int i=0;i<st.length();i++) {

if(st.charAt(i)==32||st.charAt(i)=='.'||st.charAt(i)==','||st.charAt(i)=='!'||
i==st.length()-1) {

c++;

System.out.println("No of word="+c);

void seperateLine() {

System.out.println("-----------------------------------");

System.out.println(st);

System.out.println("-----------------------------------");

for(int i=0;i<st.length()-1;i++) {

if(st.charAt(i)!=32) {

System.out.print(st.charAt(i));

}else{

System.out.println();

System.out.print(st.charAt(st.length()-1));

}
JAVA ASSIGNMENT ROLL 05 20.12.2010

class Ass7 {

public static void main (String[] args) {

StringOperation s=new StringOperation();

Scanner s1=new Scanner(System.in);

int i=0;

while(i!=-99) {

System.out.println("\n..........Menu........");

System.out.println("1:-String insert");

System.out.println("2:-String reverse");

System.out.println("3:-Word count");

System.out.println("4:-Seperate line");

System.out.println("Type -99 for exit");

int c=s1.nextInt();

switch(c){

case 1:

s.getString();

break;

case 2:

s.reverse();

break;
JAVA ASSIGNMENT ROLL 05 20.12.2010

case 3:

s.wordCount();

break;

case 4:

s.seperateLine();

break;

default:

i=-99;

ASSIGNMENT NO . 09
JAVA ASSIGNMENT ROLL 05 20.12.2010

import java.util.*;

class StringOperation {

Scanner sc=new Scanner(System.in);

String st;

void getString() {

System.out.println("Enter a string...");

st=sc.nextLine();

void reverse() {

System.out.println("-----------------------------------");

System.out.println(st);

System.out.println("-----------------------------------");

for(int i=st.length()-1;i>=0;i--) {

System.out.print(st.charAt(i));

void wordCount() {

System.out.println("-----------------------------------");

System.out.println(st);

System.out.println("-----------------------------------");
JAVA ASSIGNMENT ROLL 05 20.12.2010

int c = 0;

for(int i=0;i<st.length();i++) {

if(st.charAt(i)==32||st.charAt(i)=='.'||st.charAt(i)==','||st.charAt(i)=='!'||
i==st.length()-1) {

c++;

System.out.println("No of word="+c);

void seperateLine() {

System.out.println("-----------------------------------");

System.out.println(st);

System.out.println("-----------------------------------");

for(int i=0;i<st.length()-1;i++) {

if(st.charAt(i)!=32) {

System.out.print(st.charAt(i));

}else{

System.out.println();

System.out.print(st.charAt(st.length()-1));

}
JAVA ASSIGNMENT ROLL 05 20.12.2010

class Ass7 {

public static void main (String[] args) {

StringOperation s=new StringOperation();

Scanner s1=new Scanner(System.in);

int i=0;

while(i!=-99) {

System.out.println("\n..........Menu........");

System.out.println("1:-String insert");

System.out.println("2:-String reverse");

System.out.println("3:-Word count");

System.out.println("4:-Seperate line");

System.out.println("Type -99 for exit");

int c=s1.nextInt();

switch(c){

case 1:

s.getString();

break;

case 2:

s.reverse();

break;
JAVA ASSIGNMENT ROLL 05 20.12.2010

case 3:

s.wordCount();

break;

case 4:

s.seperateLine();

break;

default:

i=-99;

ASSIGNMENT NO . 10
JAVA ASSIGNMENT ROLL 05 20.12.2010

/*

*To check whether a matrix is symmetric or not.

*/

import java.util.Scanner;

class SymMat {

int a[][],n;

Scanner sc=new Scanner(System.in);

void getVal() {

System.out.print("Enter the order of the matrix=");

n=sc.nextInt();

a=new int[n][n];

System.out.println("Enter the values=");

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

a[i][j]=sc.nextInt();

void check() {

int m=0;
JAVA ASSIGNMENT ROLL 05 20.12.2010

System.out.println("Matrix=");

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("Transpose Matrix=");

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

System.out.print(a[j][i]+" ");

System.out.println();

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

if(a[i][j]!=a[j][i]) {

m=1;

break;

}
JAVA ASSIGNMENT ROLL 05 20.12.2010

if(m==0)

System.out.println("\nSymmetric Matrix");

else

System.out.println("\nNot Symmetric Matrix");

class Ass8 {

public static void main(String[] args) {

SymMat s=new SymMat();

s.getVal();

s.check();

ASSIGNMENT NO . 11
JAVA ASSIGNMENT ROLL 05 20.12.2010

/*

*To check whether a matrix is symmetric or not.

*/

import java.util.Scanner;

class SymMat {

int a[][],n;

Scanner sc=new Scanner(System.in);

void getVal() {

System.out.print("Enter the order of the matrix=");

n=sc.nextInt();

a=new int[n][n];

System.out.println("Enter the values=");

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

a[i][j]=sc.nextInt();

void check() {

int m=0;
JAVA ASSIGNMENT ROLL 05 20.12.2010

System.out.println("Matrix=");

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("Transpose Matrix=");

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

System.out.print(a[j][i]+" ");

System.out.println();

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

if(a[i][j]!=a[j][i]) {

m=1;

break;

}
JAVA ASSIGNMENT ROLL 05 20.12.2010

if(m==0)

System.out.println("\nSymmetric Matrix");

else

System.out.println("\nNot Symmetric Matrix");

class Ass8 {

public static void main(String[] args) {

SymMat s=new SymMat();

s.getVal();

s.check();

ASSIGNMENT NO . 12
JAVA ASSIGNMENT ROLL 05 20.12.2010

import java.util.Scanner;

class SkewSymMat {

Scanner sc=new Scanner(System.in);

int a[][],b[][],n;

void getVal() {

System.out.print("\nEnter the order of the matrix=");

n=sc.nextInt();

a=new int[n][n];

System.out.println("Enter values...");

for(int i=0;i<a.length;i++) {

for(int j=0;j<a.length;j++) {

a[i][j]=sc.nextInt();

void check() {

b=new int[n][n];

int s=0;

System.out.println("Matrix..");

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {
JAVA ASSIGNMENT ROLL 05 20.12.2010

System.out.print(" "+a[i][j]+" ");

System.out.println();

System.out.println("Transpose of the matrix..");

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

b[i][j]=a[j][i];

System.out.print(" "+b[i][j]+" ");

System.out.println();

for(int i=0;i<n;i++) {

for(int j=0;j<n;j++) {

if(a[i][j]!=-(b[i][j])) {

s=1;

break;

if(s==0)

System.out.println("Skew Symmetric Matrix");


JAVA ASSIGNMENT ROLL 05 20.12.2010

else

System.out.println("Not Skew Symmetric Matrix");

class Ass9 {

public static void main(String[] args) {

SkewSymMat m=new SkewSymMat();

m.getVal();

m.check();

ASSIGNMENT NO . 13
JAVA ASSIGNMENT ROLL 05 20.12.2010

import java.util.*;

//Matrix multiplication

class MatrixMultiplication {

int a[][],b[][],c[][],r1,r2,c1,c2;

Scanner sc=new Scanner(System.in);

void getVal() {

System.out.println("Enter the row and clumn of the 1st matrix=");

r1=sc.nextInt();

c1=sc.nextInt();

a=new int[r1][c1];

System.out.println("Enter the values of 1st matrix=");

for(int i=0;i<r1;i++) {

for(int j=0;j<c1;j++) {

a[i][j]=sc.nextInt();

System.out.println("Enter the row and clumn of the 2nd matrix=");

r2=sc.nextInt();

c2=sc.nextInt();

b=new int[r2][c2];

System.out.println("Enter the values of 2nd matrix=");

for(int i=0;i<r2;i++) {
JAVA ASSIGNMENT ROLL 05 20.12.2010

for(int j=0;j<c2;j++) {

b[i][j]=sc.nextInt();

void showMatrix() {

System.out.println("1st Matrix=");

for(int i=0;i<r1;i++) {

for(int j=0;j<c1;j++) {

System.out.print(a[i][j]+" ");

System.out.println();

System.out.println("2st Matrix=");

for(int i=0;i<r2;i++) {

for(int j=0;j<c2;j++) {

System.out.print(b[i][j]+" ");

System.out.println();

void mul() {
JAVA ASSIGNMENT ROLL 05 20.12.2010

if(c1==r2){

System.out.println("Column of 1st Matrix equals to row of 2nd


Matrix.");

c=new int[r1][c2];

for(int i=0;i<r1;i++) {

for(int j=0;j<c2;j++) {

int s=0;

for(int k=0;k<c1;k++) {

s=s+a[i][k]*b[k][j];

c[i][j]=s;

System.out.println("Result=");

for(int i=0;i<r1;i++) {

for(int j=0;j<c2;j++) {

System.out.print(c[i][j]+" ");

System.out.println();

else
JAVA ASSIGNMENT ROLL 05 20.12.2010

System.out.println("Column of 1st Matrix not equals to row of 2nd


Matrix.");

class Ass10 {

public static void main (String[] args) {

MatrixMultiplication m=new MatrixMultiplication();

m.getVal();

m.showMatrix();

m.mul();

ASSIGNMENT NO . 14

/*
JAVA ASSIGNMENT ROLL 05 20.12.2010

* Constructor overloading.

*/

import java.util.Scanner;

import java.math.*;

class Volume{

Volume(double h,double l,double b){

System.out.print("\nVolume of Room="+h*l*b);

Volume(double r,double h){

System.out.print("\nVolume of Cylinder="+3.14*Math.pow(r, 2)*h);

Volume(double c) {

System.out.println("\nVolume of Cube="+Math.pow(c, 3));

class Ass11 {

public static void main(String[] args) {

Volume v1=new Volume(10,15,11);

Volume v2=new Volume(5,20);

Volume v3=new Volume(10);


JAVA ASSIGNMENT ROLL 05 20.12.2010

ASSIGNMENT NO . 15

import java.util.*;
JAVA ASSIGNMENT ROLL 05 20.12.2010

//Volume calculation

class Volume {

double h,l,b,r;

void calculation(double h, double l, double b) {

System.out.print("\nVolume of a room is:-"+h*l*b);

void calculation(double h, double r) {

System.out.println("\nVolume of cylinder:-"+3.14*Math.pow(r, 2)*h);

class Ass12 {

public static void main(String[] args) {

Volume v=new Volume();

Scanner sc=new Scanner(System.in);

double h,l,b;

System.out.println("Enter the height,length and breadth of room=");

h=sc.nextDouble();

l=sc.nextDouble();

b=sc.nextDouble();

v.calculation(h, l, b);

System.out.println("\nEnter the height and radius of cylender=");


JAVA ASSIGNMENT ROLL 05 20.12.2010

h=sc.nextDouble();

b=sc.nextDouble();

v.calculation(h, b);

ASSIGNMENT NO . 16

import java.util.Scanner;
JAVA ASSIGNMENT ROLL 05 20.12.2010

class Function{

int nCr(int n,int r){

return(fact(n)/(fact(r)*fact(n-r)));

int fact(int f){

if(f==0)

return 1;

else

return(f*fact(f-1));

void printData(int n){

for(int i=0;i<n;i++){

for(int k=1;k<=n-i-1;k++)

System.out.print(" ");

for(int j=0;j<=i;j++){

System.out.print(nCr(i,j)+" ");

System.out.println();

}
JAVA ASSIGNMENT ROLL 05 20.12.2010

class Ass14{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

Function f=new Function();

System.out.println("Enter the line nos....");

int n=sc.nextInt();

System.out.println("Pascle triangle is.......");

f.printData(n);

You might also like