Write a statement in Java, to declare a constant MAX and store the value 100 in it
Answers
Answered by
5
Answer:
To make any variable a constant, we must use 'static' and 'final' modifiers in the following manner
EXAMPLE:-
import java.util.Scanner;
public class ConstantExample1
{
//declaring constant
private static final double PRICE=234.90;
public static void main(String[] args)
{
int unit;
double total_bill;
System.out.print("Enter the number of units you have used: ");
Scanner sc=new Scanner(System.in);
unit=sc.nextInt();
total_bill=PRICE*unit;
System.out.println("The total amount you have to deposit is: "+total_bill);
}
}
Similar questions
English,
18 days ago
India Languages,
18 days ago
Biology,
1 month ago
Social Sciences,
9 months ago