Write a Java application that ask the user to enter two integers, and prints their sum, product, difference and quotient (division).
[Use Scanner class present in java.util package and nextInt () method to read input].
Write a Java application that inputs from the user the radius of a circle as an integer and prints the circle's diameter, circumference and area using floating point value 3.1459 for pi. You may also use constant Math.PI for the value of pi. Class Math defined in package java.lang.
[Note: Use Scanner class present in java.util package and nextInt () method to red input].
3. Write a Java Application that inputs from the user temperature in Fahrenheit as an float and converts in to its equivalent Celsius temperature and print the result.(Formula:c=(f-32)*5/9)
[Note: Use Scanner class present in java.util package and nextFloat () method to red input].
import java.util.Scanner;
public class Applications {
public static void main(String[] args){
System.out.print("Enter first integer : ");
int firstInteger = new Scanner(System.in).nextInt();
System.out.print("Enter second integer : ");
int secondInteger = new Scanner(System.in).nextInt();
System.out.println();
System.out.println("Sum : "+(firstInteger+secondInteger));
System.out.println("Product : "+(firstInteger*secondInteger));
System.out.println("Difference : "+(firstInteger-secondInteger));
System.out.println("Quotient : " +(firstInteger/secondInteger));
System.out.println();
System.out.print("Enter radius of circle : ");
int radius = new Scanner(System.in).nextInt();
System.out.println();
System.out.println("Diameter : "+2*radius);
System.out.println("Circumference : "+2*Math.PI*radius);
System.out.println("Area : "+Math.PI*radius*radius);
System.out.println();
System.out.print("Enter temperature in Fahrenheit : ");
float fahrenheitTemperature = new Scanner(System.in).nextFloat();
float celsiusTemperature = (fahrenheitTemperature-32)*5/9;
System.out.println("\nTemperature in celsius: "+celsiusTemperature);
}
}
Comments
Leave a comment