Assignment No - 07
Assignment No - 07
Assignment No - 07
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 {
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 {
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");
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 {
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 {
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");
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
/*
*/
import java.util.Scanner;
class SymMat {
int a[][],n;
void getVal() {
n=sc.nextInt();
a=new int[n][n];
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
class Ass8 {
s.getVal();
s.check();
ASSIGNMENT NO . 11
JAVA ASSIGNMENT ROLL 05 20.12.2010
/*
*/
import java.util.Scanner;
class SymMat {
int a[][],n;
void getVal() {
n=sc.nextInt();
a=new int[n][n];
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
class Ass8 {
s.getVal();
s.check();
ASSIGNMENT NO . 12
JAVA ASSIGNMENT ROLL 05 20.12.2010
import java.util.Scanner;
class SkewSymMat {
int a[][],b[][],n;
void getVal() {
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.println();
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
b[i][j]=a[j][i];
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)
else
class Ass9 {
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;
void getVal() {
r1=sc.nextInt();
c1=sc.nextInt();
a=new int[r1][c1];
for(int i=0;i<r1;i++) {
for(int j=0;j<c1;j++) {
a[i][j]=sc.nextInt();
r2=sc.nextInt();
c2=sc.nextInt();
b=new int[r2][c2];
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){
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
class Ass10 {
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{
System.out.print("\nVolume of Room="+h*l*b);
Volume(double c) {
class Ass11 {
ASSIGNMENT NO . 15
import java.util.*;
JAVA ASSIGNMENT ROLL 05 20.12.2010
//Volume calculation
class Volume {
double h,l,b,r;
class Ass12 {
double h,l,b;
h=sc.nextDouble();
l=sc.nextDouble();
b=sc.nextDouble();
v.calculation(h, l, b);
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{
return(fact(n)/(fact(r)*fact(n-r)));
if(f==0)
return 1;
else
return(f*fact(f-1));
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{
int n=sc.nextInt();
f.printData(n);