Sunday, 5 November 2017

java problems with solution



Write . Write a program that converts pounds into kilograms.
The program prompts the user to enter a number in pounds, converts it
to kilograms, and displays the result
Description:
One pound is 0.454 kilograms
Solution
import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
   float pound;
   System.out.println("Enter the mass in pound");
   pound=in.nextFloat();
   System.out.println("The mass in kilogram ="+(pound*.454));
 
 }
}
Output:

java programmimg



Problem 07:
Write a program that reads a number in feet, converts it
to meters, and displays the result. One foot is 0.305 meter.
Description:
It is very simple feet multiplied by 0.305
Solution
import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
   float feet,meter;
   System.out.println("Enter the distance in feet");
   feet=in.nextFloat();
   meter=feet*0.305f;
   System.out.println("The area of clyinder = "+meter);
 
 }
}
Output
                        

         

java program very important programs



 Write a program that reads in the radius
and length of a cylinder and computes the area and volume
Description:
using the following
formulas:
area = radius * radius * p
volume = area * length
Solution
 import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
   float radius,area,lenght,pi=3.14f;
   System.out.println("Enter the radius");
   radius=in.nextFloat();
   System.out.println("Enter the lenght");
   lenght=in.nextFloat();
   area=pi*radius*radius;
   System.out.println("The area of clyinder = "+area);
   System.out.println("The volume of clyinder ="+(area*lenght));
 }
}

Output
                   

java program that solve the quadratic formula



Problem 04:
Write a program that display the result of quadratic formula
Description:
By using Math.sqrt();
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
   double a,b,c,x;
   System.out.println("Enter the value of a   b   and   c");
   a=in.nextDouble();
   b=in.nextDouble();
   c=in.nextDouble();
   x = (-b+Math.sqrt(b*b-(4*a*c)))/  (2*a);
   System.out.println("The final result is = "+x);
 }
}
Output