Class 9
Class 9
99 */
class Q1_i
{
public static void main()
{
int i;
for(i=1;i<=99;i=i+2)
{
if(i==99)
System.out.print(i);
else
System.out.print(i+",");
}
}
}
}
System.out.println("Sum of the series=" +sum);
}
}
}
System.out.println("Sum of the series=" +product);
}
}
}
System.out.println("Sum of the series ="+sum);
}
}
}
}
}
System.out.println("Sum of the series = "+sum);
}
}
}
System.out.println("Sum of the series = "+sum);
}
}
}
}
/* Write a program to input a number and check whether it is a neon number or not. if a number such
that the sum of digits of the
number is equal to the number , then it is called a Neon number.
Example : 9
9 * 9 =81 , 8+1=9
So 9 is a neon number
*/
import java.util.*;
class Q3
{
public static void main()
{
int number,square,sum=0,rem;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
number= sc.nextInt();
square=number*number;
while(square>0)
{
rem=square%10;
sum=sum+rem;
square=square/10;
}
if(sum==number)
System.out.println(number+" is a neon number");
else
System.out.println(number+" is not a neon number");
}
}
/* Write a program to input a number and print the digits seperated by comma(,).
* Example 3456
* output : 6,5,4,3
*/
import java.util.*;
class Q4
{
public static void main()
{
int number,rem;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
number= sc.nextInt();
while(number>0)
{
rem=number%10;
number=number/10;
if(number>0)
System.out.print(rem+",");
else
System.out.print(rem);
}
}
}
/* Write a program to input a number and display the new number after reversing the digits of the
original number. The
program also displays the absolute difference between the original number and the reversed number.
Sample Input : 194
Sample output : 491
Absolute difference = 297
*/
import java.util.*;
class Q5
{
public static void main()
{
int number,reverse=0,difference,rem,temp;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
number=sc.nextInt();
temp=number;
while(temp>0)
{
rem=temp%10;
reverse=reverse*10+rem;
temp=temp/10;
}
difference=Math.abs(number-reverse);
System.out.println("Reverse number is = "+reverse);
System.out.println("Absolute difference is ="+difference);
}
}
/* Write a program to input a number and check whether the number is a Disarium Number or not.
* A number will be called Disarium if the sum of its digits powered by their respective position is equal
to the original
* number. Example 135
* 1pow 1 + 3 pow 2 + 5 pow 3 =1+9+125=135
*/
import java.util.*;
class Q6
{
public static void main()
{
int number,rem, sum=0, temp,digits=0;
System.out.println("Enter a number");
Scanner sc= new Scanner(System.in);
number=sc.nextInt();
temp=number;
while(temp>0) // counting the digits in number
{
rem=temp%10;
temp=temp/10;
digits++;
}
temp=number;
while(temp>0)
{
rem=temp%10;
sum=sum+(int)Math.pow(rem,digits);
digits--;
temp=temp/10;
}
if(sum==number)
System.out.println(number+" is a Disarium number");
else
System.out.println(number+" is not a Disarium number");
}
}
/* Write a program to input a number and print whether the number is a palindrome number or not. A
number is said to be
* Palindrome when its reverse is equal to the number itself.
* Example 141, 414, 595 etc.
*/
import java.util.*;
class Q7
{
public static void main()
{
int number,reverse=0,rem,temp;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
number=sc.nextInt();
temp=number;
while(temp>0)
{
rem=temp%10;
reverse=reverse*10+rem;
temp=temp/10;
}
if(reverse==number)
System.out.println(number+" is a palindrome number");
else
System.out.println(number+" is not a palindrome number");
}
}
/* Print sum of series a pow 1+ a pow 2 + a pow 3+.........+ a pow n where a and n entered by user */
import java.util.*;
class Q8_i
{
public static void main()
{
int a,n,sum=0,i;
Scanner sc=new Scanner(System.in);
System.out.println(" Enter the value of a");
a=sc.nextInt();
System.out.println(" Enter the value of n");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
sum=sum+(int)Math.pow(a,i);
}
System.out.println("Sum of series ="+sum);
}
}
/* Print the sum of the series 1* x pow 2 + 2* x pow 2+ 3* x pow 2 + 4* x pow 2 + .......+ n* x pow 2 */
import java.util.*;
class Q8_ii
{
public static void main()
{
int x,n,sum=0,i;
Scanner sc=new Scanner(System.in);
System.out.println(" Enter the value of x");
x=sc.nextInt();
System.out.println(" Enter the value of n");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
sum=sum+i*(int)Math.pow(x,2);
}
System.out.println("Sum of series ="+sum);
}
}
/* Print the product of the series 1pow 1 * 2 pow 2 * 3 pow 3 * ........ * n pow n */
import java.util.*;
class Q8_iii
{
public static void main()
{
int i,n,product=1;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the value of n");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
product=product*(int)Math.pow(i,i);
}
System.out.println("Product of the series = "+product);
}
}
}
}
/* Print the sum of the series 2/2! + 4/4! + 6/6! + 8/8! + 10/10! */
class Q8_v
{
public static void main()
{
double i,j,fact=1.0,sum=0.0;
for(i=2.0;i<=10.0;i=i+2.0)
{
fact=1.0;
for(j=i;j>=1.0;j--)
{
fact=fact*j;
}
System.out.println(fact);
sum=sum+(i/fact);
}
System.out.println("Sum of the series = "+sum);
}
}
/* Print the sum of the series a/sqrt 2 + a/sqrt 4 + a/sqrt 6 +.........+ a/sqrt 10 */
import java.util.*;
class Q8_vi
{
public static void main()
{
double i,sum=0.0,a;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the value of a ");
a=sc.nextDouble();
for(i=2.0;i<=10.0;i=i+2.0)
{
sum=sum+(a/Math.sqrt(i));
}
System.out.println(" Sum of the series = "+sum);
}
}
/* print the sum of the series a pow 1 - a pow 2 + a pow 3 - a pow 4 + a pow 5 ....... a pow n */
import java.util.*;
class Q8_vii
{
public static void main()
{
double a,n,sum=0,i;
int sign=-1;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the value of a");
a=sc.nextDouble();
System.out.println("Enter the value of n");
n=sc.nextDouble();
for(i=1.0;i<=n;i++)
{
sign=sign*-1;
sum=sum+sign*Math.pow(a,i);
}
System.out.println("Sum of the series = "+sum);
}
}
/* Write a program to input a number and print whether the number is Niven number or not.
A niven number is the number which is divisible by the sum of its digits.
Example 111 is a Niven number because it is divisible by sum of its digits i.e 1+1+1=3
*/
import java.util.*;
class Q9
{
public static void main()
{
int number,sum=0,rem,temp;
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number");
number=sc.nextInt();
temp=number;
while(temp>0)
{
rem=temp%10;
sum=sum+rem;
temp=temp/10;
}
if(number%sum==0)
System.out.println(number+" is a Niven number");
else
System.out.println(number+" is not a Niven number");
}
}
/* Write a program to input a number and check whether it is an automorphic number or not. An
automorphic number is a number
whose square ends in the same digits as the original number.
Example 76 , square of 76 = 5776
25, square of 25 = 625
5 , square of 5 = 25
6 , square of 6=36
examples 0, 1, 5, 6, 25, 76, 376, 625, 9376, 90625, 109376, 890625, 2890625, 7109376, 12890625,
87109376,
212890625, 787109376, 1787109376, 8212890625, 18212890625, 81787109376, 918212890625,
9918212890625, 40081787109376
*/
import java.util.*;
class Q10
{
public static void main()
{
long number, temp, digits=0,rem,square;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number");
number=sc.nextLong();
temp=number;
while(temp>0) // digits count
{
rem=temp%10;
digits++;
temp=temp/10;
}
temp=number;
square=temp*temp;
if(square%Math.pow(10,digits)==number)
System.out.println(number+" is an automorphic number");
else
System.out.println(number+" is not an automorphic number");
}
}
/* Write a program to input a number and print whether the number is a Krishnamurthy number or not.
A krishnamurthy number is a number whose sum of the factorial of its digits is equal to the number
itself.
Example 1,2,145,40585
*/
import java.util.*;
class Q11
{
public static void main()
{
long number, temp,rem,fact=1,sum=0;
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number");
number=sc.nextLong();
temp=number;
while(temp>0)
{
rem=temp%10;
for(long i=rem;i>=1;i--)
{
fact=fact*i;
}
sum=sum+fact;
fact=1;
temp=temp/10;
}
if(sum==number)
System.out.println(number+" is a Krishnamurthy number");
else
System.out.println(number+" is not a Krishnamurthy number");
}
}
/* Write a menu driven program to print the following series according to user's choice using switch
statement
(i) 1+12+123+1234+12345
(ii) 1/1 * 2/4 * 3/9 * ......*nth term
*/
import java.util.*;
class Q12
{
public static void main()
{
int choice ,i,n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter your choice 1 or 2");
choice=sc.nextInt();
switch(choice)
{
case 1:
int term=0;
for(i=1;i<=5;i++)
{
term=term*10+i;
if(i==5)
System.out.print(term);
else
System.out.print(term+"+");
}
break;
case 2:
System.out.println("Enter the number of terms");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
if(i==n)
System.out.print(i+"/"+i*i);
else
System.out.print(i+"/"+i*i+" * ");
}
}
}
}
/* Write a menu driven program to input n and print the sum of the following series
(i) s= x+ x pow 2 / !2 + x pow 3 / !3 + ........n
(ii) s= 1/ 1 pow 3 - 1/ 2 pow 3 + 1/ 3 pow 3 ..........1/ n pow 3
*/
import java.util.*;
class Q13
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter your choice 1 OR 2");
int choice=sc.nextInt();
switch(choice)
{
case 1:
double sum=0.0;
int n,x;
long fact=1;
System.out.println("Enter the value of x");
x=sc.nextInt();
System.out.println("Enter the number of terms");
n=sc.nextInt();
for(int i=1;i<=n;i++)
{
fact=1;
for(int k=i;k>=1;k--)
{
fact=fact*k;
}
sum=sum+(Math.pow(x,i)/fact);
}
System.out.println("Sum of series =" +sum);
break;
case 2:
int terms,sign=-1;
double total=0.0;
System.out.println("Enter the number of terms");
terms=sc.nextInt();
for(int i=1;i<=terms;i++)
{
sign=sign*(-1);
total=total+sign*(1/Math.pow(i,3));
}
System.out.println("Sum of series ="+total);
break;
default :
System.out.println("Wrong Choice !");
}
}
}
/* Write a menu driven program to perform the following(use switch case statement)
(a) To print the series 0,3,8,15,24,....n terms (Value of n is to be input by the user)
(b) To find the sum of the series given below :
S = 1/2 + 3/4 + 5/6 + 7/8 + ....... + 19/20
*/
import java.util.*;
class Q14
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter your choice 1 OR 2");
int choice = sc.nextInt();
switch(choice)
{
case 1:
int n;
System.out.println("Enter the number of terms");
n=sc.nextInt();
for(int i=1;i<=n;i++)
{
if(i==n)
System.out.print((i*i)-1);
else
System.out.print((i*i)-1+",");
}
break;
case 2 :
double S=0.0;
for(double i=1;i<=19;i=i+2)
{
S=S+(i/(i+1));
}
System.out.println("Sum of the series =" +S);
break;
default :
System.out.println("Wrong Choice !!!!");
}
}
}
/* Write a program to input a number and print whether the number is a Duck Number or not.
* A duck number is a number that has at least one zero present in it.
* Example : 3210 , 7056, 8430709 are all duc numbers.
*/
import java.util.*;
class Q15
{
public static void main()
{
long number,count=0,rem,temp;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
number=sc.nextLong();
temp=number;
while(temp>0)
{
rem=temp%10;
if(rem==0)
{
count++;
}
temp=temp/10;
}
if(count==0)
System.out.println(number+" is not a duck number");
else
System.out.println(number+" is a duck number");
}
}
(ii) To find and display the factorial of a number input by the user
number = 5
output : 120
*/
import java.util.*;
class Q16
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter your choice 1 OR 2 ");
int choice = sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter a number");
int n=sc.nextInt();
for(int i=1;i<n;i++)
{
if(n%i==0)
System.out.print(" "+i);
}
break;
case 2:
System.out.println("Enter a number");
int number = sc.nextInt();
long fact=1;
if(number==0)
System.out.println("Factorial value of 0 is always 1");
if(number<0)
System.out.println("No factorial value of a negative number");
if(number>0)
{
for(int i=number;i>=1;i--)
{
fact=fact*i;
}
System.out.println("Factorial value of "+number+" is "+fact);
}
break;
default :
System.out.println("Wrong Choice !!!!");
}
}
}
/* Write a program to input a number and find the smallest digit in the number
example : number =6524
smallest digit =2
*/
import java.util.*;
class Q17
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number");
int number=sc.nextInt();
int temp=number;
int smallest=9,rem=0;
while(temp>0)
{
rem=temp%10;
if(rem<smallest)
smallest=rem;
temp=temp/10;
}
System.out.println("Smallest digit in "+number+" is " +smallest);
}
}
/* Write a program to input a number and check whether it is a prime palindrome number or not.
A prime palindrome number is a positive integer that is prime as well as palindrome.
Example : 131 , 151, 181 , 191 etc.
*/
import java.util.*;
class Q18
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number");
int number = sc.nextInt();
int i,count=0,reverse=0, rem=0,temp=number;
// Checking prime number or not
for(i=1;i<=number;i++)
{
if(number%i==0)
{
count++;
}
}
// Checking palindrome number or not
while(temp>0)
{
rem=temp%10;
reverse=reverse*10+rem;
temp=temp/10;
}
if(count==2&&reverse==number)
System.out.println(number+" is a prime palindrome number");
else
System.out.println(number+" is not a prime palindrome number");
}
}
if(i==n-2)
System.out.print(new_term);
else
System.out.print(new_term+",");
}
break;
case 2:
System.out.println("Enter the number");
int number=sc.nextInt();
int product=1;
while(number>0)
{
int rem=number%10;
if(rem%2==0)
product=product*rem;
number=number/10;
}
System.out.println("Product of even digits ="+product);
break;
default :
System.out.println("Wrong Choice !!!!");
}
}
}
}
}