Write a program in java to input distance travelled by a passenger.Calculate the distance and the fare to be paid.
upto 10 km- fixed charge 80 rupees
11km to 12 km-6 rupees/km
21 to 30km-5rupees/km
31 to 40 km-4 rupees/km
Answers
Answer:
import java.util.*;
class dis
{
public static void main ()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter The Distance - ");
int n = in.nextInt();
if(n <= 10)
System.out.println("Total charges 80");
else if(n >= 11 && n <= 20)
System.out.println("Total charges "+(n*6));
else if(n >= 21 && n <= 30)
System.out.println("Total charges "+(n*5));
else if(n >= 31 && n <= 40)
System.out.println("Total charges "+(n*4));
}
}
Explanation:
we have taken a input check the condition and if it true then we are printing the charge.
-----------------(Extra for information)-
NOTE : In system.out.print you have to add something then give bracket else this will happen .
int h = 1;
int k = 2;
System.out.print("The sum is "+h+k);
output - The sum is 12
This is wrong method
the right method -
int h = 1;
int k = 2;
System.out.print("The sum is "+(h+k));
output - The sum is 3
----------------------------------------------------------------
please give vote and mark as brainlist