Java Arithmetic Operator Question 4

Question

What is the output of the following code?

System.out.println("25 / 4 is " + 25 / 4); 
System.out.println("25 / 4.0 is " + 25 / 4.0); 
System.out.println("3 * 2 / 4 is " + 3 * 2 / 4); 
System.out.println("3.0 * 2 / 4 is " + 3.0 * 2 / 4); 


25 / 4 is 6
25 / 4.0 is 6.25
3 * 2 / 4 is 1
3.0 * 2 / 4 is 1.5

Note

public class Main {
  public static void main(String[] args) {
    System.out.println("25 / 4 is " + 25 / 4); 
    System.out.println("25 / 4.0 is " + 25 / 4.0); 
    System.out.println("3 * 2 / 4 is " + 3 * 2 / 4); 
    System.out.println("3.0 * 2 / 4 is " + 3.0 * 2 / 4); 
  }/*from w w w  . jav a  2  s. com*/
}



PreviousNext

Related