The document contains 7 Java programs written by Ankit Gupta. The programs include:
1) A program to print two strings on separate lines
2) A program to find the multiplication and geometric mean of 4 input numbers
3) A program to calculate the volume of a cylinder given its height and radius
4) A program to convert centimeters to feet and inches
5) A program to convert seconds to hours, minutes and seconds
6) A program to determine if the roots of a quadratic equation are real, complex, equal or distinct
7) The author's name and information is included before each program
1. Name –AnkitGupta,Roll no-16 B.tech Sem-5th
Thisprogram iswrittenbyAnkitGupta.
Assignment:1
/*
Write a JAVA program to print the following in the separate line
Hello World
Welcome to Faculty of Engineering & Technology
*/
public class P1
{
public static void main(String[] args) {
System.out.println("Hello World");
System.out.println("Welcome to Faculty of Engineering & Technology");
}
}
/*
2. Name –AnkitGupta,Roll no-16 B.tech Sem-5th
Thisprogram iswrittenbyAnkitGupta.
Write a JAVA program to find the multiplication of given 4 numbers. Also find their geometric
mean.
*/
import java.util.Scanner;
public class P2
{
public static void main(String[] args) {
System.out.print("Enter four numbers: ");
Scanner sc=new Scanner(System.in);
int n[]=new int[4];
for(int i=0;i<n.length;i++)
n[i]=sc.nextInt();
int mul=1;
for(int i=0;i<n.length;i++)
mul=mul*n[i];
double gm=Math.pow(mul,1.0/n.length);
System.out.println("Multiplication of 4 no. is "+mul);
System.out.println("Geometric mean of 4 no. is "+gm);
}
}
4. Name –AnkitGupta,Roll no-16 B.tech Sem-5th
Thisprogram iswrittenbyAnkitGupta.
/*
Write a JAVA program which reads the value of the height and radius of the base of a cylinder
and calculates
the Volume of that cylinder.
*/
import java.util.Scanner;
public class P3
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the height of cylinder = ");
int h=sc.nextInt();
System.out.print("Enter the radius of cylinder = ");
int r=sc.nextInt();
double v=3.14*(r*r)*h;
System.out.println("Volume of the Cylinder = "+v);
}
}
5. Name –AnkitGupta,Roll no-16 B.tech Sem-5th
Thisprogram iswrittenbyAnkitGupta.
/*
Given as input a floating (real) number of centimeters, print out the equivalent number of feet
(integer) and
inches (floating, 1 decimal), with the inches given to an accuracy of one decimal place.
Assume 2.54 centimeters per inch, and 12 inches per foot. If the input value is 333.3, the output
format should
be: 333.3 centimeters is 10 feet 11.2 inches.
*/
import java.util.Scanner;
public class P4 {
public static void main(String[] args) {
int feet;
double temp,cent,inch;
System.out.print("Enter the number in centimeter : ");
Scanner sc = new Scanner(System.in);
cent = sc.nextDouble();
inch = cent/2.54;
double d=inch%12;
System.out.printf((int)(inch/12)+" foot %.1f inch",d);
}
}
6. Name –AnkitGupta,Roll no-16 B.tech Sem-5th
Thisprogram iswrittenbyAnkitGupta.
/*
Given as input an integer number of seconds, print as output the equivalent time in hours,
minutes and
seconds. Recommended output format is something like 7322 seconds is equivalent to 2 hours
2 minutes 2
seconds.
*/
import java.util.Scanner;
public class P5
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the time in seconds = ");
int t=sc.nextInt();
int s=t%60;
t=t/60;
int m=t%60;
int h=t/60;
System.out.print("Time is"+h+" hours "+m+" minutes "+s+" Seconds");
7. Name –AnkitGupta,Roll no-16 B.tech Sem-5th
Thisprogram iswrittenbyAnkitGupta.
}
}
/*
Write a JAVA program to find the roots of the quadratic equation and display a message that
roots are equal
or distinct or real or complex.
*/
import java.util.Scanner;
public class P6
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Coefficient of x^2 = ");
int a=sc.nextInt();
System.out.print("Enter the Coefficient of x^1 = ");
int b=sc.nextInt();
System.out.print("Enter the Constant = ");
int c=sc.nextInt();
double d=(b*b)-4*a*c;
8. Name –AnkitGupta,Roll no-16 B.tech Sem-5th
Thisprogram iswrittenbyAnkitGupta.
if(d>0)
System.out.print("Roots are real and distinct");
if(d==0)
System.out.print("Roots are real and equal");
if(d>0)
System.out.print("Roots are imaginary");
}
}