Showing posts with label Model Paper. Show all posts
Showing posts with label Model Paper. Show all posts

Sunday, January 20, 2008

Quadratic Equation

Wap to input the values of three coefficients of a quadratic equation
AX(Square)+BX+C=0
Find the roots of the Equation and display them , stating wether they are real,imaginary or equal
Also print the value of X

import java.io.*;
class Quadratic
{
public int a,b,c;
public void Quadratic()throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter the value A");
int a = Integer.parseInt(br.readLine());
System.out.println(" Enter the value B ");
int b = Integer.parseInt(br.readLine());
System.out.println(" Enter the value C ");
int c = Integer.parseInt(br.readLine());
}
public void Values()
{
double x1,x2;
int z = (b*b)-(4*a*c);
if(z>0)
{
System.out.println(" Real Roots ");
x1=(-b+Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println( " Root 1 " + x1);
x2=(-b-Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println( " Root 2 " + x2);
}
else if(z==0)
{
System.out.println(" Equal Roots ");
x1= (b)/(2*a);
System.out.println(" Root = " +x1);
}
else if(z<0)
{
System.out.println(" Imaginary Roots ");
}
}
public static void main(String args[])throws IOException
{
Quadratic Q = new Quadratic();
Q.Quadratic();
Q.Values();
}
}

Saturday, January 19, 2008

String based Program

Write a Program to accept a String and print it in following manner
Input - Harsh Kumar Agrawal ( Just an Example)
Output - H.K.Agrawal






Frequency Of Vowels In the String

Q Write a Program to Find the Number of times vowels Occure in a given String

Method 1 - Of anshul
import java.io.*;
class vowels{ public static void main()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String str;
int i,c=0,j;
System.out.println("Enter a string");
str=in.readLine();
str=str.toLowerCase();
for(i=0;i<=str.length()-1;i++)
{
j=str.charAt(i);
if(j==' ')
{
if((j+1)=='a'(j+1)=='e'(j+1)=='i'(j+1)=='o'(j+1)=='u')
c++;
}
}
if(str.charAt(0)=='a'str.charAt(0)=='e'str.charAt(0)=='i'str.charAt(0)=='o'str.charAt(0)=='u')
c++;
System.out.println("\n no. of words starting with vowels::::"+c);
}
}

Method 2 (By Harsh)(me :))
import java.io.*;
class Proverbial
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter a String ");
String s=br.readLine();
char ch;
s=s.toLowerCase();
int c=0,l=s.length();
for(int i=0;i
{
ch=s.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
c++;
}
System.out.println(" Frequency of Vowels is "+ c);
}
}





Wednesday, January 16, 2008

Perfect Number

A perfect Integer is a number which is equal to the sum of all its factors
eg - 28 is a perfect integer as it is the sum of all its factor -
1 + 2 + 4 + 7 + 14 = 28
Wap to display perfeect integers form 1 to 1000
Evergreen Publications Model Paper1 Q9


[2D array]Sum of Even and Odd

WAP a program to find the product of all the even elements and all the odd elements present in the array

//Wap to Store 12 elements in a array of size 3X4 and find the sum of all the elements
//and product of even elements and odd elements.

import java.io.*;
class EvenOdd
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[3][4];
int s=0,even=1,odd=1;
System.out.println(" Enter 12 elements for array one :");
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
s=s+a[i][j];
if(a[i][j]%2==0)
even=even*a[i][j];
else
odd=odd*a[i][j];
}
}
System.out.println(" Sum = " +s);
System.out.println(" Product of Even = " + even );
System.out.println(" Product of odd = " + odd);
}
}