I need to make a basic program where this is the outcome. It needs to do all the
ID: 3782868 • Letter: I
Question
I need to make a basic program where this is the outcome. It needs to do all the things in the pictures not that the numbers on the side are my inputs.
Enter a character: 5 Enter value for double value x: 5.77 Enter value for integer value y: 2 Enter value for integer value z: 3 Your character is 5 Your value for x is 5.77 Your value for y is 2 Your value for z is 3 The reciprocal of x is 0.17331 x/z is 1.92333 x y z is 10.77 The reciprocal of y is 0.5 The reciprocal of z is 0.333333 y/z is 0 y modulus z is 2Explanation / Answer
NumbersDemo.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class NumbersDemo {
public static void main(String[] args) {
//Declaring variables
char ch;
double x;
int y,z;
//Creating DecimalFormat class object
DecimalFormat df=new DecimalFormat("#.#####");
//Scanner Object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Getting the inputs entered by the user
System.out.print("Enter a Character :");
ch=sc.next(".").charAt(0);
System.out.print("Enter value for double value x:");
x=sc.nextDouble();
System.out.print("Enter value for integer value y:");
y=sc.nextInt();
System.out.print("Enter value for integer value z:");
z=sc.nextInt();
//Displaying the inputs entered by the user
System.out.println(" Your Character is "+ch);
System.out.println("Your Value for x is "+x);
System.out.println("Your Value for y is "+y);
System.out.println("Your Value for z is "+z);
//Displaying the outputs
System.out.println(" The Reciprocal of x is "+df.format(1/x));
System.out.println("x/z is "+df.format(x/z));
System.out.println("x+y+z is "+(x+y+z));
double resY=(double)1/y;
double resZ=(double)1/z;
System.out.println(" The Reciprocal of y is "+df.format(resY));
System.out.println("The Reciprocal of z is "+df.format(resZ));
System.out.println("y/z is "+(y/z));
System.out.println("y modulus z is "+(y%z));
}
}
____________________
Output:
Enter a Character :5
Enter value for double value x:5.77
Enter value for integer value y:2
Enter value for integer value z:3
Your Character is 5
Your Value for x is 5.77
Your Value for y is 2
Your Value for z is 3
The Reciprocal of x is 0.17331
x/z is 1.92333
x+y+z is 10.77
The Reciprocal of y is 0.5
The Reciprocal of z is 0.33333
y/z is 0
y modulus z is 2
_________Thank You