Blogroll

This blog is created for education about engineering students.All the engineering students are get free downloadable books here. not only books and also different software also available here

Java program for the quadratic equation ax2 + bx + c = 0


Week1 :
a) Write a Java program that prints all real solutions to the quadratic equation ax2 + bx + c = 0. Read in a, b, c and use the quadratic formula. If the discriminate b2-4ac is negative, display a message stating that there are no real solutions.

import java.io.*;
import java.io.*;
class root
{
  public static void main(String args[])throws IOException
  {
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   int a=Integer.parseInt(br.readLine());
   int b=Integer.parseInt(br.readLine());
   int c=Integer.parseInt(br.readLine());
   int d=((b*b)-(4*a*c));
    if(d>0)
   {
    system.out.print("roots are real and distinct");
    }
  if(d==0)
  {
   system.out.print("roots are real");
  }
  if(d<0)
  {
  system.out.print("there is no solution");
  }
 }
}



b) Write a Java program that uses both recursive and non recursive functions to print the nth value in the Fibonacci sequence.


import java.io.*;
import java.lang.*;
class fibonacci
{
  public static void main(String args[]) throws IOException
  {
   int a=Integer.parseInt(args[0]);
   int b=Integer.parseInt(args[1]);
   int n=Integer.parseInt(args[2]);
   int c=0;
   while(c
   {
    c=a+b;
   system.out.print(c);
   a=b;
   b=c;
  }
 }
}

No comments:

Post a Comment

Total Pageviews