Monday, October 25, 2021

A program that determines whether an input number is an integer or a real number in java

 write a program that determines whether an input number is an integer or a real number.

Three sample runs of this program are as follows:

Enter a number: 50

The number 50 is an integer.

Enter a number: 50.0

The number 50 is an integer.

Enter a number: 50.75

The number 50.75 is a real number.

HINTS: Use only ONE variable for the input. You will also need to separate the real part (after the decimal point) of the input and the integer part (before the decimal point). Think about how you will do this.


Code:

public class NumberTypeLab5{
    public static void main(String[] args) {
     int x =25;
     x = x*100;
     if(x/100==0){
      System.out.println("Number is not integer: " + x);
     }  
     else{
      System.out.println("Number is integer: " + x);
     }
  }}

No comments:

Post a Comment

String Array and passing method in java

 In this task, we pass a method and also cover the passing String Array to the method. Code:   import java.util.Scanner; public class String...