Advertisement
rajath_pai

Cognizant

Jun 15th, 2022
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7.     public static void main (String[] args) throws java.lang.Exception
  8.     {
  9.         Scanner sc = new Scanner(System.in);
  10.         String c = sc.nextLine();
  11.         String bill = sc.nextLine();
  12.         int amt = sc.nextInt();
  13.         int ans = 0;
  14.         for(int i = 0; i < bill.length(); i++){
  15.             if(Character.isDigit(bill.charAt(i)) == false) {
  16.                 System.out.println("invalid bill number");
  17.                 System. exit(1);
  18.             }
  19.             ans += bill.charAt(i) - '0';
  20.         }
  21.         System.out.println(ans);
  22.         if(bill.length() == 6 && ans != 0){
  23.             if(ans % 2 == 0){
  24.                 System.out.println("Total bill amout is "+(amt*0.9));
  25.  
  26.             }
  27.             else{
  28.                 System.out.println("Total bill amout is "+amt);
  29.                 System.out.println("Congratulations!! You are selected for lucky draw");
  30.             }
  31.         }
  32.         else{
  33.             System.out.println("invalid bill number");
  34.             System. exit(1);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement