Write a java program
to find the sum of the series : 1+ x+ x2+x3+….
import java.util.Scanner;
class SumSeries
{
public static void main(String
arg[])
{
Scanner
in = new Scanner(System.in);
int
n;
System.out.println("enter
the nTH element ");
n
= in.nextInt();
int
i=0;
int
sum=0;
int
x;
System.out.println("enter
the power of the series");
x
= in.nextInt();
while(i<n)
{
sum+=Math.pow(x,i);
i++;
}
System.out.println("x="+x+"Sum
of the seriees 1+x+x^2.s..="+sum);
}
}
-------------------------------------------------------------------------------------------------------------------------------
Write a java program to define a class called Cone
and find its area and volume. The area and volume of the cone are evaluated
using the formula:
Slant
height = sqrt( r 2+h2) , volume = (1/ 3) .pi r 2
h, area = pi. r .sqrt( r 2+h2) .
-----------------------------------------------------------------------------------------------------------------
import
java.util.Scanner;
public
class Cone
{
public static void main(String[]
args)
{
double pi = 3.145;
Scanner in = new Scanner(System.in);
System.out.println("Enter the
radius: ");
double radius = in.nextDouble();
System.out.print("Enter the
height: ");
double height = in.nextDouble();
double slheight;
double volume;
double area;
slheight = Math.sqrt(radius*radius +
(height*height));
volume = (pi*radius*radius*height)/3;
area =
(pi*radius*Math.sqrt(radius*radius+height*height));
System.out.println("slantheight
=is" + slheight);
System.out.println("volume is =
" +volume);
System.out.println("Area is
=" + area);
}
}
------------------------------------------------------------------------------------------------------------------
Write a java program
to read 2 sides (float values) and included angle value (theta: radian of float
type) of a triangle. Find the area of the triangle.
-------------------------------------------------------------------------------------------------------------
//Thu 17 Sep 2015 16:01:11 IST
coded by clinton
import java.util.Scanner;
class AreaTriangle
{
public static void main(String args[])
{
Scanner
in = new Scanner(System.in);
System.out.println("Enter the value
of 1st side: ");
float a = in.nextFloat();
System.out.println("Enter
the value of 2ed side");
float
b = in.nextFloat();
System.out.println("Enter
the value of angle");
float
teta= in.nextFloat();
double
area = ( 0.5*(a*b*(Math.sin(teta))));
System.out.println("The
Area of a Triangle is: "+area);
}
}
Write a java program to find the volume and surface
area of a cylinder by accepting its radius and height.
------------------------------------------------------------------------------------------------------------
//Thu 17 Sep 2015 15:31:55
IST coded by clinton.m.u
import java.util.Scanner;
class VolCyli
{
public static void main(String args[])
{
Scanner
in = new Scanner(System.in);
System.out.println("Enter the
radius: ");
double radius = in.nextDouble();
System.out.println("Enter
the hight");
double
hight = in.nextDouble();
double
surface_area = (2*(Math.PI *radius*hight))+(2*(Math.PI*radius*radius));
System.out.println("The
Surface area of a clylinder is: " + surface_area);
double
volume = (Math.PI*radius*radius*hight);
System.out.println( "The voulme of
the clylinder is:"+volume) ;
}
}
------------------------------------------------------------------------------------------------------------
Write a program
to find the area and volume of the sphere by accepting the radius.
---------------------------------------------------------------------------------------------------
//Thu
17 Sep 2015 15:49:35 IST coded by
clinton
import
java.util.Scanner;
class
VolSphere
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the
radius: ");
double radius = in.nextDouble();
double area =
(4*(Math.PI*radius*radius));
System.out.println("The area of a sphere is: " + area);
double volume =
((4/3)*Math.PI*radius*radius*radius);
System.out.println( "The voulme of
the sphere is:"+volume) ;
}
}
Write a java program
to find the area and circumference of the circle by accepting the values for
radius of the circle.
//Thu 17 Sep 2015 11:36:01 IST
coded by clinton.m.u
import java.util.Scanner;
class CircleCircum
{
public static void main(String args[])
{
Scanner
in = new Scanner(System.in);
System.out.print("Enter the radius:
");
double radius = in.nextDouble();
double
area = Math.PI * (radius * radius);
System.out.println("The
area of circle is: " + area);
double circumference= Math.PI * 2*radius;
System.out.println( "The
circumference of the circle is:"+circumference) ;
}
}
Write a java program
to accept more than one string and arrange them in alphabetical order.
–----------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public
class Alphabetical_Order
{
public static void main(String[]
args)
{
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter number
of words you want to enter:");
n = s.nextInt();
String words[] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("please
Enter all the words:");
for(int i = 0; i < n; i++)
{
words[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n;
j++)
{
if
(words[i].compareTo(words[j])>0)
{
temp = words[i];
words[i] = words[j];
words[j] = temp;
}
}
}
System.out.println("Words in
Sorted Order:");
for (int i = 0; i < n - 1; i++)
{
System.out.print0(words[i] +
",");
}
System.out.println(words[n - 1]);
System.out.println();
}
}
No comments:
Post a Comment