Search This Blog

Buzz Number in MATLAB & JAVA

Definition:

number is said to be Buzz Number if it ends with 7 or is divisible by 7.

Example: 

1)1007 is a Buzz Number as it end with 7

2)77777 is also a Buzz Number as it ends with 7 and also it is divisible by 7.


3) 21 is Buzz number as it is divisible by 7

Matlab Code:


x=input('Enter the number');
m=x;
Y=[];
while(m>0)
    b=rem(m,10);
    Y=[Y b];
    m=(m-b)/10;
end
if(Y(1)==7 || rem(x,7)==0)
    disp('YES , the number is Buzz number');
else
    disp('No , the number is not Buzz number');

end

Explanation:




JAVA CODE:

import java.util.Scanner;
class Who
{
public static void main(String args[])
{
Scanner obj=new Scanner(System.in);
System.out.println("Enter the number:");
int b=0;
int n=obj.nextInt();
int m=n;
int c=n%7;
b=m%10;
if(b==7 || c==0)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}


OUTPUT:






Reference Video(Digit extraction from a number in MATLAB)






No comments