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 intpi and 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
0
Answer:
Explanation:
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
0
Answer:
public class Main{
double pi = 3.14159;
public static void main(String[] args){
System.out.println("the first five decimal places" + pi);
}
}
Explanation:
we can convert a double into an int but java will take away the fractional part of the double that means if we convert double to int with pi as the double the out will be only 3 and not 3.1459 we can convert double to int like this : 'int intValue = (int) doubleValue;'
which will give us 3 if the double value is 3.1459
Similar questions