Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to test whether an integer n equals 10 and whether a floating-po

ID: 3788971 • Letter: W

Question

Write a program to test whether an integer n equals 10 and whether a floating-point number is approximately equal to 10. (In Java)

Hints:

You could do this by prompting the user for an integer.
Then see if that integer equals 10.
Display on the screen "## is (not) equal to 10" where ## is the number the user typed in.

Create a double variable y that is equal to the user's integer divided by a number (2, 3, or 4 would be good choices).
Display on the screen "## divided by 2 is ..." (use the user's integer, and your chosen number, and display the quotient).
You could accomplish this with something like System.out.println("## divided by 2 is " + y);

Multiply the quotient y by your number and see if the result is equal to 10.
Use the EPSILON constant we discussed in class (see "Common Error 3.2" on page 91) to make this determination.
Display on the screen "## is (not) equal to 10" where ## is the quotient times 2 (or whatever number you chose to use).

Explanation / Answer

public class example
{
public static void main(String ar[])
{
System.out.println("enter a digit:");
   int digit=sc.nextInt();
   if(digit==10){
       System.out.println("the digit:"+digit+ "is equal 10");
       return;
   }
   else{
       System.out.println("the digit:"+digit+ "is not equal 10");
       double y=digit/2;
       System.out.println("the digit:"+digit+ "and divided by 2 and quotient is:"+y);
       double val=y*digit;
       int data=(int)val;
       if(data==digit){
           System.out.println("the quotinet digit:"+data+ "is equal 10");
       }else
           System.out.println("the quotient digit:"+data+ "is not equal 10");
      
   }
     
}

}
output:
enter a digit:
20
the digit:20is not equal 10
the digit:20and divided by 2 and quotient is:10.0
the quotient digit:200is not equal 10

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote