Computer Science, asked by bhan61, 1 year ago

Write a Program to declare a float variable pi and initialize it with the value of pi till 5 decimal places. Declare an integer variable intpiand store the value of pi in it. You have to print the value of intpi.

Keep the name of your class as Main
Use the System.out.println()statement for printing. Print only the value of intpi

Answers

Answered by nitish8089
9
public class Main{

public static void main(String...args){

float pi=3.14159f;

int intpi=(int)pi;

System.out.println(intpi);

}

}

// output:::3
Answered by surajnegi0600
0

Answer:

Program to declare a float variable pi and initialize it with the value of pi till 5 decimal places.

public class Main {

   public static void main(String[] args) {

       float pi = 3.14159f;

       int intpi = (int) pi;

       System.out.println(intpi);

   }

}

Explanation:

In this program, we first declare a float variable pi and initialize it with the value of pi till 5 decimal places. Then, we declare an integer variable intpi and store the value of pi in it by casting the float variable to int. Finally, we use the System.out.println() statement to print the value of intpi, which is 3 in this case.

Note that when you cast a float variable to int variable it trucate the decimal part, that's why we only get 3 as intpi.

More questions and answers

https://brainly.in/question/54954907

https://brainly.in/question/54916009

#SPJ3

Similar questions