Write a programme to compute the telegram charges as follows:
Words Charges
Up to 15 words Rs.5/-
More than 15 words Rs.1/word
Accept a string as telegram message and the character ('n' for normal and 'e' for express) to calculate the telegram charge.
import java.util.*; public class Telegram { public static void main(String []args) { Scanner sc=new Scanner(System.in); System.out.print("Enter A String : "); String str=sc.nextLine(); String []words=str.split(" "); int len=words.length; double amt=5.0; if(len>15) { amt += (len-15); } System.out.print(" Total Charge : " + amt); } }
Enter A String : On the Insert tab, the galleries include items that are designed.
Total Charge : 5.0
Enter A String : On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document.
Total Charge : 20.0