CISCE
Program to find out the sum of Buzz Number between the range from A to B.
import java.util.*;
class Buzz
{
Scanner sc=new Scanner(System.in);
int s=0;
public int sum(int A, int B)
{
for(int i=A;i<=B;i++)
{
if ( i % 10 == 7 || i % 7 == 0 )
{
s=s+i;
}
}
return s;
}
public static void main(String args[ ])
{
Buzz ob = new Buzz();
int buzz_number=ob.sum(4,16);
System.out.println(" sum of Buzz Number="+buzz_number);
}
}
A disarium number is a number in which the sum of the digits to the power of their respective position is equal to the number itself.
Example: 135 = 11 + 32 + 53
Hence, 135 is a disarium number.
Design a class DisariumNumber to check if a given number is a disarium number or not.
import java.util.*;
public class DisariumNumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number (n>0) : ");
int num = sc.nextInt();
// Copy Original Number to temporary variable
int temp = num;
int d = 0;
long sum = 0;
// Convert Number to String to retrieve each digit
String s = String.valueOf(num);
// Retrieve the length of entered number
int len = s.length();
while (temp > 0) {
// extracting the last digit
d = temp % 10;
// Calculate sum
sum = sum +(int) Math.pow(d, len);
len--;
temp = temp/10;
}
if (sum == num) {
System.out
.println("***** " + num + " is a Disarium Number. ******");
}
else {
System.out.println("***** " + num + " is not a Disarium Number. ******");
}
}
}
Java program to find out the Palindrome Number for N.
import java.util.*;
public class PalindromeNumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n, rev = 0, digit;
System.out.println(" Enter the Number to find out the Palindrome Number ");
n=sc.nextInt();
int original=n;
while( n != 0 )
{
digit = n % 10;
rev = rev * 10 + digit;
n =n/10;
}
if (rev == original)
System.out.println(original + " is a palindrome.");
else
System.out.println(original + " is not a palindrome.");
}
}
Java program to odd and Even Number in N Limit
import java.util.Scanner;
class OddEven
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the limit");
int num= sc.nextInt(); int x;
for(x=0;x<=num;x++)
{
if(x%2==0)
System.out.println("even no.s=" + x );
else
{
System.out.println("odd no.s=" + x );
}
}
}
}
Check whether the input number is pronic or not??
import java.util.*;
class PronicNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int n = sc.nextInt();
int k = (int)(Math.sqrt(n));
if(k*(k+1)==n)
System.out.println(n+" is a Pronic Number.");
else
System.out.println(n+" is not a Pronic Number.");
}
}