package Program;/**** @author Dilip*/import java.io.*;import java.util.*;public class BreakStringToWord{String str;int count = 0;public BreakStringToWord(){try{InputStreamReader ir = new InputStreamReader(System.in);BufferedReader br = new BufferedReader(ir);System.out.print("Enter String: ");str = br.readLine();System.out.println("Enter String is : "+ str);System.out.println("Breaking this string is : ");StringTokenizer token = new StringTokenizer(str);while (token.hasMoreTokens()){count++;str = token.nextToken();System.out.println(str);}System.out.println("Number of Words : "+ count);}catch(IOException e){}}public static void main(String[] args) {BreakStringToWord c = new BreakStringToWord();}}Output:run:Enter String: dilip bariEnter String is : dilip bariBreaking this string is :dilipbariNumber of Words : 2
Write a program to calculate the total expenses. Quantity and price per item are input by the user and discount of 10% is offered if the expense is more than 7000.
#include<iostream.h> #include<conio.h> void main() { int totalexp, qty, price, discount; cout<<" Enter quantity: "; cin>>qty; cout<<" Enter price: "; cin>>price; totalexp=qty*price; if (totalexp>7000) { discount=(totalexp*0.1); totalexp=totalexp-discount; } cout<<" Total Expense is Rs. "<<totalexp; getch(); }
Comments
Post a Comment