WEEK-1
1)Write a java program that prints all real solutions to the quadratic equations ax 2 +bx+c=0 read a,b,c and
use the quadratic formula if the discriminant is b 2-4ac is negative display a message stating that there are
no real solutions.
AIM:-To print all real solutions of the quadratic equations and to display that there are no real solutions.
CODE:-
import java.util.*;
class Quad
public static void main(String args[])
int a,b,c,k;
double x,y,l;
Scanner sc=new Scanner(System.in);
System.out.println("enter a,b and c values");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
k=b*b-4*a*c;
if(k<0)
System.out.println("there is no real number"+k);
else
l=Math.sqrt(k);
x=(-b-l)/2*a;
y=(-b+l)/2*a;
1
System.out.println("it is a real number"+x+" "+y);
OUTPUT:-
2)The fibinacci sequence is defined by the following rulews are 1st sequence are 1 and 1 and subsequent
values are sum of 2 values are preceding values.
AIM:-To print the fibonacci sequence starting with 1 and 1.
CODE:-
import java.util.*;
class Fib
public static void main(String args[])
int x=1,y=1,z,n,i;
Scanner sc=new Scanner(System.in);
System.out.println("enter n value");
n=sc.nextInt();
System.out.println(x+" "+y);
2
for(i=2;i<n;i++)
z=x+y;
System.out.println(" "+z);
x=y;
y=z;
OUTPUT:-
3)Write a java program to print sum of two numbers using scanner class.
AIM:-To print sum of two numbers.
CODE:-
import java.util.*;
class Sum
public static void main(String args[])
3
int x,y,z;
Scanner sc=new Scanner(System.in);
System.out.println("enter x value");
x=sc.nextInt();
System.out.println("enter y value");
y=sc.nextInt();
z=x+y;
System.out.println("sum of two number is"+z);
OUTPUT:-
4)Write a java program to implement given number is even or odd using scanner class.
AIM:-To print the given number is even or odd.
CODE:-
import java.util.*;
class Evenodd
public static void main(String args[])
4
int n;
Scanner sc=new Scanner(System.in);
System.out.println("enter n value");
n=sc.nextInt();
if(n%2==0)
System.out.println("even number is"+n);
else
System.out.println("odd number is"+n);
OUTPUT:-