Advertisement
Ishu_15hu

Java_Exersice(1)

Apr 12th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package javaapplication6;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class JavaApplication6 {
  7.    
  8.         public static boolean CheckFor(int n)
  9.         {
  10.             while(n>0)
  11.             {
  12.                 if(n%10==8)
  13.                 {
  14.                     return true;
  15.                 }
  16.                 n/=10;
  17.             }
  18.             return false;
  19.         }
  20.  
  21.  
  22.    
  23.     public static void main(String[] args) {
  24.         int n,sum=0;
  25.      
  26.         Scanner sc= new Scanner(System.in);
  27.         n= sc.nextInt();
  28.         if(n!=-1)
  29.         {
  30.             while(n>-1)
  31.             {
  32.                 if(CheckFor(n)==true)
  33.                 {
  34.                     sum+=n;
  35.                 }
  36.                 n=sc.nextInt();
  37.             }
  38.            
  39.         }
  40.         System.out.println(sum);
  41.     }
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement