Nested for Loop



Example Programs



Program [1]

Write a program to input 10 integers and find the sum of the prime numbers only.


View Solution

Program [2]

Write a program to input 10 integers and find the average of the prime numbers only.


View Solution

Program [3]

Write a program to input 10 integers and find the sum of the perfect numbers only.


View Solution

Program [4]

Write a program to input 10 integers and find the average of the perfect numbers only.


View Solution

Program [5]

Write a program to input 10 integers and find the largest prime number if any.


View Solution

Program [6]

Write a program to input 10 integers and find the smallest perfect number if any.


View Solution

Program [7]

Write a program to generate all 2 digit prime numbers.


View Solution

Program [8]

Write a program to generate all perfect numbers between 1 to 100.


View Solution

Program [9]

Write a program to generate all 3 digit palindrome numbers.


View Solution

Program [10]

WAP to Input an integer and check whether it is a special number or not.

A special number is such a number whose sum of the factorials of each digit is the number itself. For example, 145 is a special number because 1! + 4! + 5! = 1 + 24 +120 = 145. Special numbers are also called factorion.


View Solution

Program [11]

Write a program to input a number and check whether it is a magic number or not. If you iterate the process of summing the squares of the decimal digits of the number, and if this process terminates in 1, then the original number is called a magic number. For example 55=> (5+5)=10=>(1 +0)=1.


View Solution

Program [12]

Write a program to input an integer as argument, and print the number by having the digits arranged in ascending order.


View Solution

Program [13]

Write a program to pass an integer as argument, and check whether all digits in it are unique or not.


View Solution

Program [14]

Write a program to pass an integer as argument, and print the frequency of each digit in it.


View Solution

Program [15]

Write a program to input 10 numbers and print the largest prime number if any.


View Solution

Program [16]

Write a program to generate all 2 digit twisted prime number. Twisted prime number is a number which is prime and its reverse is also prime. Example 13 and 31.


View Solution

Program [17]

WAP to Input an integer and form a new number where the digits are in ascending order.


View Solution

Program [18]

Write a program to pass an integer as argument and print the second largest digit


View Solution

Program [19]

Write a program to print Floyd's triangle as shown below:

1

2  3

4  5  6

7  8  9  10

11 12 13 14 15


View Solution

Program [20]

Write a Java program to print Following Pattern:



View Solution

Program [21]

Write a Java program to print Following Pattern:



View Solution

Program [22]

Write a Java program to print Following Pattern:



View Solution

Program [23]

Write a Java program to print Following Pattern:



View Solution

Program [24]

Write a Java program to print Following Pattern:



View Solution

Program [25]

Write a Java program to print Following Pattern:



View Solution

Program [26]

Write a Java program to print Following Pattern:



View Solution

Program [27]

Write a program in java to print all prime Palindrome numbers between 'm' and 'n'

Sample Example:

Enter the value of m :

1

Enter the value of n :

1000

Prime Palindrome number between 1 and 1000 are: 

2 3 5 7 11 101 131 151 181 191 313 353 373 383 727 757 787 797 919 929 

Solution 1:

import java.util.*;
class PrimePalindrome
{
  public static void main(String arr[])
  {
      Scanner sc=new Scanner(System.in);
      int m,n,i,a,digit,rev;
      boolean flag;
      System.out.println("Enter the value of m :");
      m=sc.nextInt();
      System.out.println("Enter the value of n :");
      n=sc.nextInt();
      System.out.println("Prime Palindrome number between "+m+" and "+n+" are: ");
      for(i=m;i<=n;i++)
      {
          a=i;
          rev=0;
          while(a>0)
          {
              digit=a%10;
              rev=rev*10+digit;
              a=a/10;
          }
          if(i==rev)
          {
              flag=true;
              for(a=2;a<i;a++)
              {
                  if(i%a==0)
                  {
                      flag=false;
                      break;
                  }
              }
              if(flag==true&&i>1)
              {
                  System.out.print(i+" "); 
              }
          }
      }
  }
}

Solution 2: Using Function

import java.util.*;
class PrimePalindrome
{
  boolean isPrime(int n)
  {
      int a;
      for(a=2;a<=n/2;a++)
      {
          if(n%a==0)
            return false;
      }
      if(n==1)
        return false;
      else
        return true;
  }
  boolean isPalindrome(int n)
  {
      int rev=0,t;
      t=n;
      while(t>0)
      {
          rev=rev*10+(t%10);
          t=t/10;
      }
      if(rev==n)        
        return true;
      else
        return false;
  }
  public static void main(String arr[])
  {
      Scanner sc=new Scanner(System.in);
      int m,n,i,a,digit,rev;
      PrimePalindrome obj=new PrimePalindrome();
      boolean flag;
      System.out.println("Enter the value of m :");
      m=sc.nextInt();
      System.out.println("Enter the value of n :");
      n=sc.nextInt();
      System.out.println("Prime Palindrome number between "+m+" and "+n+" are: ");
      for(i=m;i<=n;i++)
      {
          if(obj.isPalindrome(i)&&obj.isPrime(i))
          {
                System.out.print(i+" ");
          }
          
      }
  }
}

View Solution

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Website development Company in Allahabad Sarkari Exam Quiz