Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Loop or Control Structure Statement in Java:-


It is used to enumerate large statements of data using a single repeatable block. Loop is also called control Structure.

It is used to solve range-based problems, for example, we want to display marks of 5000 students then we will use Loop


Loop is mostly used in Array and Collection type variables.


Loop is also called control structure because it will provide a common block that will be controlled by the condition.

It is also called iterative statements because it will iterate the program code under the common repeatable block of code.




Loop uses three statements for program execution


                                  Forward                                 Backward

initialization  :-         i= min                                     i=max


Condition :-              i<=max                                    i>=min    


Iteration                    i++                                           i--




Type of Loop:-


1) Entry Control:-

     First Check Condition Then Execute Statements

     1.1) while:-   

This loop will work when the condition will be true, while loop can be used to create a finite and infinite based program both.

     but we mostly prefer infinite-based programs using while because for loop provide simple structure to implement the finite based program.



Syntax of While Loop:-


 initialization;

while(condition)   
{
      Statement;
      increment;

}


example

int i=1;

while(i<=10)
{
    System.out.println(i);
   i++;

}



infinite  while loop example using break

int i=1;

while(true)
{
    if(i>10)
    break;
    System.out.println(i);
   i++;

}

infinite  while loop example using a boolean value

class TableExample
{
    public static void main(String args[])
    {
         int i=1;
         int num=35;
         boolean flag=true;
         while(flag)
         {
             
              System.out.println(num*i);
              i = i+1;
               if(i>10)
                flag=false;
         }

    }

}

Program of While Loop to calculate a table to understand while loop properly:-

import java.util.Scanner;
class Table
{
   public static void main(String args[])
   {
       int num,i;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number for table");
       num=sc.nextInt();
       i=1;
       while(i<=10)
       {
          System.out.println(num+ "*" + i + "=" + (num*i));
          i++;

       }
      System.out.println("Total number of step "+i);


   }


}

WAP to create a table of any number using infinite Loop:-

import java.util.Scanner;
class Table
{
   public static void main(String args[])
   {
       int num,i;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number for table");
       num=sc.nextInt();
       i=1;
       while(true)
       {
          System.out.println(num+ "*" + i + "=" + (num*i));
          if(i>10)
           break;
          i++;

       }
     // System.out.println("Total number of step "+i);


   }


}


limitation of while loop:-

1)  Complex structure hence it can not be managed in nested sequence easily.

2)  take more process time to program execution  as compared to for loop




           
   

 1.2 for -

using this we can contain all sub-statements using for statements, it provides a simple syntax structure as compared to a while and do-while loop.

for loop is mostly used to create a finite condition-based program.


flow of for loop:-

      1        2              4
for(init; condition; iteration)
 {
        3
        statement; 
 }



finite for loop example:-


import java.util.Scanner;
class Table
{
   public static void main(String args[])
   {
       int num,i;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number for table");
       num=sc.nextInt();
       
       for(i=1;i<=10;i++)
       {
          System.out.println(num+ "*" + i + "=" + (num*i));
        
         

       }
     // System.out.println("Total number of step "+i);


   }


}


Infinite for loop example:-

import java.util.Scanner;
class Table
{
   public static void main(String args[])
   {
       int num,i;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number for table");
       num=sc.nextInt();
       i=1;
       for(;;)
       {
          System.out.println(num+ "*" + i + "=" + (num*i));
          if(i>10)
           break;
          i++;

       }
     // System.out.println("Total number of step "+i);


   }


}


Write a program to calculate the factorial of any entered number?

import java.util.Scanner;
class Fact
{
   public static void main(String args[])
   {
       int num,i,f=1;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number for table");
       num=sc.nextInt();
       
       for(i=1;i<=num;i++)
       {
         f=f*i;  #f = 120
        
       }
      System.out.println("result is "+f);


   }


}


Nested For Loop:-   We will write more than one for loop using a nested sequence, it Contains a collection of outer for loop and multiple inner for loop.


for(init;condition;iteration)
{
   for(init;condition;iteration)
   {
            Statement;

  }
 
}

1  2 3 4 5
1 2 3 4
1 2 3
1 2
1
.....................................................................................................

I       j
1      5
2      4
3      3
4      2
5      1


Solution:-

class NestedLoop
{
    public static void main(String... args)
    {
      for(int i=1;i<=5;i++) 
      {
          for(int j=1;j<=6-i;j++) 
           {

                System.out.print(j+ "  ");

            }
            System.out.println();

      }

     }

}

......................................................

A B C D E
A B C D
A B C 
A B
A
...............................................
The solution of This Program:-

class NestedLoop
{
    public static void main(String... args)
    {
      for(int i=69;i>=65;i--)    
      {
          for(int j=65;j<=i;j++)    
           {

                System.out.print((char)j+" ");

            }
            System.out.println();

      }

     }

}


A B C D E
a b c d
A B C
a b
A


The solution to this program:-

class NestedLoop
{
    public static void main(String args[])
    {
      for(int i=69;i>=65;i--)    
      {
      
          for(int j=65;j<=i;j++)    
           {
                if(i%2!=0)
                System.out.print((char)(j)+" ");
                else
                System.out.print((char)(j+32)+" ");

            }
            System.out.println();

      }

     }

}

.........................................................

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
.........................................................................

1 0 0 1 0
1 0 0 1
1 0 0
1 0
1
...................................................................................
A a B b C
A a B b
A a B
A a
A

The solution to this program:-

class NestedLoop
{
   public static void main(String ram[])
   {
       for(int i=1;i<=5;i++)
       {
            char ch=65;  
            for(int j=5;j>=i;j--)
            {
                   if(j%2!=0)
                   System.out.print((char)ch +" ");
                   else
                   {
                   System.out.print((char)(ch+32)+" "); 
                   ch++;
                   } 
                    
            }   
            System.out.println();

       }

   }


}
............................................................................

1 2 3 4 5
5 4 3 2
1 2 3
5 4
1
.....................................................................................







2)Exit Control:-

    First, execute the loop then check the condition

   2.1) do-while

      Syntax of do-while

       initialization;
       do
       {
              Statement; 
              Increment;
       }while(condition);

WAP to print 1 to 10?

class Dowhile
{

 public static void main(String args[])
 {
        
        int num, i;
      
        i=1;
        do
        {
         System.out.println(i);
         i++;

       }while(i<=10);


  }

}


 WAP to print the table of any entered number?

import java.util.Scanner;

class Dowhile
{

 public static void main(String args[])
 {
        Scanner sc = new Scanner(System.in);
        int num,i;
        System.out.println("enter number to print table");
        num=sc.nextInt();
        i=1;
        do
        {
         System.out.println(num*i);
         i++;

       }while(i<=10);


  }

}


WAP to print factorial of any entered number?

import java.util.Scanner;
class Dowhile
{

 public static void main(String args[])
 {
        Scanner sc = new Scanner(System.in);
        int num,i,f=1;
        System.out.println("enter number to print fact");
        num=sc.nextInt();
        i=num;

        do
        {
         f=f*i;
         i--;

       }while(i>=1);

       System.out.println("Factorial is "+f);


  }

}

ASSIGNMENT:-

1)  WAP   to calculate the sum of one digit positive number?


2) WAP to reverse pin code?



3)  WAP to find the max digit is Pincode?


4) WAP to check prime?


class Checkprime
{

 public static void main(String args[])
 {
     int num=6,c=0;
     int i=1;
     while(i<=num)
     {
        if(num%i==0)
        c++;
        i++;


     }

     if(c==2)
     System.out.println("prime");
     else
     System.out.println("not prime");


}

}


Same program using for loop?

class Checkprime
{

 public static void main(String args[])
 {
     int num=6,c=0;
   
     for(int i=1;i<=num;i++)
     {
        if(num%i==0)
        c++;
     }

     if(c==2)
     System.out.println("prime");
     else
     System.out.println("not prime");


}

}


Optimize Program to Check Prime Number?

class Checkprime
{

 public static void main(String args[])
 {
     int num=6,c=0;
   
     for(int i=2;i<num;i++)
     {
        if(num%i==0)
        {
        c++;
        break;

        }

     }

     if(c==0)
     System.out.println("prime");
     else
     System.out.println("not prime");


}

}

Another way to create a prime number?


import java.util.Scanner;
class Checkprime
{
  public static void main(String args[])
  {
     int num;
     Scanner sc = new Scanner(System.in);
     System.out.println("Enter number to check prime");
     num=sc.nextInt();
     int count=0,i; 
     for(i=2;i<num;i++)
     {
         if(num%i==0)
           break;

     }
     if(num==i)
      System.out.println("Prime");
     else
      System.out.println("Not prime");   

  } 


}

import java.util.Scanner;
class Checkprime
{
  public static void main(String args[])
  {
     int num;
     Scanner sc = new Scanner(System.in);
     System.out.println("Enter number to check prime");
     num=sc.nextInt();
     int count=0,i; 
     for(i=2;i<num/2;i++)
     {
         if(num%i==0)
           break;

     }
     if(num/2==i)
      System.out.println("Prime");
     else
      System.out.println("Not prime");   

  } 


}

Prine program using do-while loop?

class TableExample
{
    public static void main(String args[])
    {
         int num=41;
         int i=2;
         do
         {
             if(num%i==0)
              {
                System.out.println("not prime");
                break;
              } 
            i++;
          }while(i<num/2);

        if((num/2)==i)
        {
           System.out.println("prime");
        }        

    }

}

5) WAP to print Fibonacci series? 

0,1,1,2,3,5,8,13




Assignment of  While Loop?


1)  WAP to check prime number using an infinite loop?


2)  WAP to print A to Z using a while loop?


3)  WAP to count total even and odd numbers in pin code using an infinite loop?


Nested For Loop Assignments:-


A B C D E
  B C D E
    C D E
      D E
        E

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2
3 5
7 11 13
17 19 23 29
................................

a e i o u
a e i o
a e i
a e
a
.................................

       *
   *   *   *
*  *   *   *   *
   *   *   *
       *


......................................................................................................................................................

Break and Continue Statement:-

https://www.shivatutorials.com/2019/09/break-and-continue-statement-in-java.html
..............................................................................................................................




129 Comments

POST Answer of Questions and ASK to Doubt

  1. 12345
    2345
    345
    45
    5
    class pp
    {
    public static void main(String args[])
    {
    for(int i=1; i<=5; i++)
    {
    for(int k=3; k<=i+1; k++)
    {

    System.out.print(" ");
    }
    for(int j=i; j<=5; j++)
    {

    System.out.print(j);
    }


    System.out.println(" ");
    }
    }
    }

    ReplyDelete
  2. /*1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1*/
    class pp
    {
    public static void main(String args[])
    {
    int stc=5,spc=0;
    for(int i=1; i<=5; i++)
    {

    for(int j=1; j<=stc; j++)
    {

    System.out.print(j);
    }
    for(int k=1; k<=spc; k++)
    {

    System.out.print(" ");
    }
    stc--;


    System.out.println(" ");
    }
    }
    }

    ReplyDelete
  3. /*A B C D E
    A B C D
    A B C
    A B
    A*/
    class pp
    {
    public static void main(String args[])
    {
    int stc=69,spc=0;
    int j;
    for(int i=1; i<=5; i++)
    {

    for( j=65; j<=stc; j++)
    {
    char c=(char)j;
    System.out.print(c);
    }

    stc--;


    System.out.println(" ");
    }
    }
    }

    ReplyDelete

  4. package Pattern;

    /**
    A B C D E
    a b c d
    A B C
    a b
    A
    * @author HP
    */
    public class Pattern3 {
    public static void main(String[] args) {
    int i,j,count;//
    for(i=69;i>=65;i--)
    {
    for(j=65;j<=i;j++)
    {
    if(i%2==0)
    {
    j=(char)(j+32);
    System.out.print((char)j+" ");
    j=j-32;
    }
    else
    System.out.print((char)j+" ");
    }

    System.out.println("");
    }





    }




    }

    ReplyDelete
  5. 12345
    5432
    123
    54
    1
    package corejava;

    public class Loop {

    public static void main(String[] args) {
    for(int i=1;i<=5;i++)

    {
    for(int j=5;j>=i;j--)

    {
    if(i%2!=0)
    System.out.print(6-j);
    else
    System.out.print(j);
    }
    System.out.println(" ");
    }
    }
    }

    ReplyDelete
  6. 12345
    5432
    123
    54
    1

    public class Loop {

    public static void main(String[] args) {
    for(int i=1;i<=5;i++)

    {
    for(int j=5;j>=i;j--)

    {
    if(i%2!=0)
    System.out.print(6-j);
    else
    System.out.print(j);
    }
    System.out.println(" ");
    }
    }
    }

    ReplyDelete
  7. WAP to calculate the sum of one digit positive number?
    import java.util.Scanner;

    public class DigitSum {

    public static void main(String[] args) {
    int m,n,sum = 0;
    Scanner sc =new Scanner(System.in);
    System.out.println("enter number");
    m =sc.nextInt();
    while(m>0)
    {
    n=m%10;
    sum=sum+n;m=m/10;

    }
    System.out.println("sum of digit" + sum);


    }

    }

    ReplyDelete
  8. WAP to reverse pin code?

    import java.util.Scanner;

    public class ReversePinCode {

    public static void main(String[] args) {
    int num=0;
    int renum=0;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter number");
    num= sc.nextInt();

    while( num != 0 )
    {
    renum= renum*10;
    renum= renum+num%2;
    num =num/10;
    System.out.println(" " + num);
    }
    }

    }

    ReplyDelete
  9. WAP to print A to Z using a while loop?

    public class Alphabets {

    public static void main(String[] args) {
    char t='a';
    while(t<='z')
    {
    System.out.println(t);
    t++;
    }

    }
    }

    ReplyDelete
  10. WAP to count total even and odd number in pin code?

    public class CountEvenOddNumber {

    public static void main(String[] args) {
    int n;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter pin code" );
    n=sc.nextInt();
    if(n%2==0)
    {
    System.out.println("the number " + n +"even");

    }
    else
    {
    System.out.println("the number" + n +"odd");
    }

    }

    }

    ReplyDelete
  11. import java.util.Scanner;
    class table
    {
    public static void main(String[]arg)
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter num");
    int num=sc.nextInt();

    int i=0;
    while(i<=10)
    {
    System.out.println(num+"*"+i+"="+(num*i));
    i++;
    }
    System.out.println("total step of i"+i);
    }
    }

    ReplyDelete
  12. import java.util.Scanner;
    class fact
    {
    public static void main(String[]arg)
    {
    int f=1;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the value");
    int num=sc.nextInt();

    for(int i=1; i<=num; i++)
    {
    f=f*i;
    System.out.println(f);
    }
    }
    }

    ReplyDelete
  13. class loop
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  14. class loop
    {
    public static void main(String[]arg)
    {
    for(int i=69; i>=65; i--)
    {
    for(int j=65; j<=i; j++)
    {
    System.out.print((char)j+"");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  15. class loop1
    {
    public static void main(String[]arg)
    {
    for(int i=69; i>=65; i--)
    {
    for(int j=65; j<=i; j++)
    {
    if(i%2!=0)
    System.out.print((char)j+ " ");
    else
    System.out.print((char)(j+32)+ " ");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  16. class loopdowhile
    {
    public static void main(String[]arg)
    {
    int num, i;

    i=1;
    do
    {
    System.out.println(i);
    i++;
    }
    while(i<=10);
    }
    }

    ReplyDelete
  17. class forloop3
    {
    public static void main(String[]arg)
    {
    for(int i=1; i<=5; i++)
    {
    for(int j=1; j<=i; j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  18. class looppp
    {
    public static void main(String[]arg)
    {
    for(int i=1; i<=5; i++)
    {
    for(int j=5; j>=i;j--)
    {


    if(i%2!=0)
    System.out.print(6-j);
    else
    System.out.print(j);



    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  19. import java.util.Scanner;
    class primeno
    {
    public static void main(String[]arg)
    {
    int temp=0;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the num...");
    int num=sc.nextInt();

    for(int i=2; i<num-1; i++)
    {
    if(num%i==0)
    {
    temp=temp+1;
    }
    }
    if(temp==0)
    {
    System.out.println(num+" is primeno");
    }
    else
    {
    System.out.println(num+" is not primeno");
    }
    }}

    ReplyDelete
  20. import java.util.Scanner;
    class primenowhileloop
    {
    public static void main(String[]arg)
    {
    int temp=0;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the num...");
    int num=sc.nextInt();
    int i=1;
    while(i<=num)
    {
    if(num%i==0)
    temp++;
    i++;
    }
    if(temp==2)
    System.out.println(num+ " is a primeno");
    else
    System.out.println(num+ " is not a primeno");

    }
    }

    ReplyDelete
  21. class Fibonacciseries
    {
    public static void main(String[]arg)
    {
    int a=0, b=1,c;

    for(int i=1; i<=10; i++)
    {
    c=a+b;
    System.out.println(c);
    a=b;
    b=c;
    }
    }
    }

    ReplyDelete
  22. class primenumberusinganinfiniteloop
    {
    public static void main(String[]arg)
    {
    int num=11, t=0;
    int i=1;
    while(i<=num)
    {
    if(num%i==0)
    t++;
    i++;
    }
    if(t==2)
    System.out.println("prime");
    else
    System.out.println("notprime");
    }
    }

    ReplyDelete
  23. WAP to print A to Z using a while loop?

    class P
    {
    public static void main(String[]arg)
    {
    int a=65;
    System.out.print((char)a+" ");
    int i=1;
    while(i<=25)
    {
    a=a+1;
    System.out.print((char)a+" ");
    i++;
    }
    }
    }

    ReplyDelete
  24. A B C D E
    B C D E
    C D E
    D E
    E

    class P
    {
    public static void main(String[]arg)
    {
    int c=64,d;
    for(int i=1; i<=5; i++)
    {
    for(int j=i; j<=5; j++)
    {
    d=c+j;
    System.out.print(" "+(char)d+" ");
    }
    System.out.println();
    for(int k=1; k<=i; k++)
    {
    System.out.print(" ");
    }
    }
    }
    }

    ReplyDelete
  25. Nitesh bamotriya

    import java.util.Scanner;
    class Table
    {
    public static void main(String args[])
    {
    int num,i;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number for table");
    num=sc.nextInt();
    i=1;
    while(i<=10)
    {
    System.out.println(num+ "*" + i + "=" + (num*i));
    i++;

    ReplyDelete
  26. Nitesh bamotriya
    import java.util.Scanner;
    class Fact
    {
    public static void main(String args[])
    {
    int num,i,f=1;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number for table");
    num=sc.nextInt();

    for(i=1;i<=num;i++)
    {
    f=f*i; #f = 120

    }
    System.out.println("result is "+f);

    ReplyDelete
  27. Nitesh bamotriya
    import java.util.Scanner;
    class Fact
    {
    public static void main(String args[])
    {
    int num,i,f=1;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number for table");
    num=sc.nextInt();

    for(i=1;i<=num;i++)
    {
    f=f*i; #f = 120

    }
    System.out.println("result is "+f);

    ReplyDelete
  28. Nitesh bamotriya
    import java.util.Scanner;
    class Checkprime
    {
    public static void main(String args[])
    {
    int num;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number to check prime");
    num=sc.nextInt();
    int count=0,i;
    for(i=2;i<num;i++)
    {
    if(num%i==0)
    break;

    }
    if(num==i)
    System.out.println("Prime");
    else
    System.out.println("Not prime");

    }

    ReplyDelete
  29. import java.util.*;
    class Infinite
    {
    public static void main(String arg[])
    {
    Scanner sc=new Scanner(System.in);
    int num= sc.nextInt();
    while(num!=0)
    {
    num=num+num;
    System.out.println(num);
    }

    }
    }

    ReplyDelete
  30. import java.util.*;
    class Fact
    {
    public static void main(String arg[])
    {
    Scanner sc=new Scanner(System.in);
    int num= sc.nextInt();
    int fact=1;
    for(int i=1;i<=num;i++)
    {
    fact=fact*i;
    System.out.println(fact);
    }


    }
    }

    ReplyDelete
  31. class exampleloop
    {
    public static void main(String args[])
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(j);
    }
    System.out.println();

    }
    }
    }


    OUTPUT:-

    1
    12
    123
    1234
    12345

    ReplyDelete
  32. class exampleloop
    {
    public static void main(String args[])
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(i);
    }
    System.out.println();

    }
    }
    }




    OUTPUT:=

    1
    22
    333
    4444
    55555

    ReplyDelete
  33. class exampleloop
    {
    public static void main(String args[])
    {
    int i,j;
    for(i=5;i>=1;i--)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    }


    output:=

    12345
    1234
    123
    12
    1

    ReplyDelete
  34. /*Prime number */
    import java.util.Scanner;
    class Prime_number
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    int number;
    number = sc.nextInt();
    int count=0;
    int i=1;
    while(i<=number)
    {
    if(number%i==0)
    {
    count++;
    }
    i++;

    }
    if(count==2)
    System.out.println("Prime");
    else
    System.out.println("Not Prime");
    }
    }

    ReplyDelete
  35. class Patt
    {
    public static void main(String[] args)
    {
    int i,j,count;//
    for(i=69;i>=65;i--)
    {
    for(j=65;j<=i;j++)
    {
    if(i%2==0)
    {
    j=(char)(j+32);
    System.out.print((char)j+" ");
    j=j-32;
    }
    else
    System.out.print((char)j+" ");
    }

    System.out.println("");
    }
    }
    }


    ----------------
    class pp
    {
    public static void main(String args[])
    {
    int stc=69,spc=0;
    int j;
    for(int i=1; i<=5; i++)
    {

    for( j=65; j<=stc; j++)
    {
    char c=(char)j;
    System.out.print(c);
    }

    stc--;


    System.out.println(" ");
    }
    }
    }
    ---------------
    class Patt
    {
    public static void main(String args[])
    {
    int i,j;
    for (i=1;i<=5;i++)
    {
    for(j=1;j<=5;j++)
    {
    if (j>=i)
    {
    System.out.print(j);
    }
    }
    System.out.println("");
    }
    }
    }



    -----------------

    ------

    ReplyDelete
  36. //WAP to find max, second max, third max number in a pincode
    Program:

    import java.util.Scanner;
    public class Main {

    public static void main(String[] args) {
    int pincode,max1=0,max2=0,max3=0,temp;
    Scanner scan=new Scanner(System.in);
    System.out.print("Enter pincode - ");
    pincode=scan.nextInt();
    while(true) {
    temp=pincode%10;
    pincode/=10;
    if(temp>max1)
    max1=temp;
    else if(temp>max2)
    max2=temp;
    else if(temp>max3)
    max3=temp;
    if(pincode==0)
    break;
    }
    System.out.print("maximum - "+max1+"\nSecond Maximum - "+max2+"\nthird maximum - "+max3);
    }

    }

    ReplyDelete
  37. // WAP to calculate factorial using while loop
    Program:

    import java.util.Scanner;
    public class Main {

    public static void main(String[] args) {

    int facto=1,num;
    Scanner scan=new Scanner (System.in);
    System.out.println("Enter a number - ");
    num=scan.nextInt();
    while(num>1) {
    facto=facto*num;
    System.out.print(num+"*");
    num=num-1;
    if(num==1)
    System.out.print(num+" = "+facto);
    }
    }

    }

    ReplyDelete
  38. // Write a program to run lift from first floor to fifth and fifth to first floor 10 times with two sec pause in each floor?
    Program:

    import java.util.Scanner;
    public class Main {

    public static void main(String[] args) {

    int i=1,j=1;
    while(i<=10) {
    while(j<=10) {
    if(j<=5) {
    System.out.println(j);
    try{Thread.sleep(2000);}catch(InterruptedException e){System.out.println(e);}
    j++;
    }
    else {
    System.out.println(11-j);
    try{Thread.sleep(2000);}catch(InterruptedException e){System.out.println(e);}
    j++;
    }
    }
    System.out.println(" "+i+"th iteration of lift is completed.\n");
    i++;
    j=1;

    }
    }

    }

    ReplyDelete
  39. // WAP to to check a number is pallindrome or not
    import java.util.Scanner;
    public class Main {

    public static void main(String[] args) {

    int num,temp1=0,temp2=0,pali=0;
    Scanner scan = new Scanner(System.in);
    System.out.print("Enter a number - ");
    num=scan.nextInt();
    temp1=num;
    while(true) {
    temp2=num%10;
    pali=pali*10+temp2;
    num=num/10;
    if(num==1) {
    pali=pali*10+num;
    if(temp1==pali)
    System.out.println("Pallindrome number");
    else
    System.out.println("Not a Pallindrome number");
    break;
    }
    }


    }

    }

    ReplyDelete
  40. // WAP to find max, second max, third max number in a pincode
    Program:
    import java.util.Scanner;
    public class Main {

    public static void main(String[] args) {
    int pincode,max1=0,max2=0,max3=0,temp;
    Scanner scan=new Scanner(System.in);
    System.out.print("Enter pincode - ");
    pincode=scan.nextInt();
    while(true) {
    temp=pincode%10;
    pincode/=10;
    if(temp>max1)
    max1=temp;
    else if(temp>max2)
    max2=temp;
    else if(temp>max3)
    max3=temp;
    if(pincode==0)
    break;
    }
    System.out.print("maximum - "+max1+"\nSecond Maximum - "+max2+"\nthird maximum - "+max3);
    }

    }

    ReplyDelete
  41. //WAP to find maximum ,second maximum and third maximum no. in pincode
    import java.util.Scanner;
    class Max {

    public static void main(String[] args) {
    int pincode,max1=0,max2=0,max3=0,temp;
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter pincode - ");
    pincode=sc.nextInt();
    while(true) {
    temp=pincode%10;
    pincode=pincode/10;
    if(temp>max1)
    max1=temp;
    else if(temp>max2)
    max2=temp;
    else if(temp>max3)
    max3=temp;
    if(pincode==0)
    break;
    }
    System.out.println("maximum - "+max1+"\nSecond Maximum - "+max2+"\nthird maximum - "+max3);
    }

    }

    ReplyDelete
  42. // WAP to find max, second max, third max number in a pincode
    Program:
    import java.util.Scanner;
    public class Main {

    public static void main(String[] args) {
    int pincode,max1=0,max2=0,max3=0,temp;
    Scanner scan=new Scanner(System.in);
    System.out.print("Enter pincode - ");
    pincode=scan.nextInt();
    while(true) {
    temp=pincode%10;
    pincode/=10;
    if(temp>max1)
    max1=temp;
    else if(temp>max2)
    max2=temp;
    else if(temp>max3)
    max3=temp;
    if(pincode==0)
    break;
    }
    System.out.print("maximum - "+max1+"\nSecond Maximum - "+max2+"\nthird maximum - "+max3);
    }

    }

    ReplyDelete
  43. //WAP to calculate factorial with complete expression
    import java.util.Scanner;
    public class Fact {

    public static void main(String[] args) {

    int factorial=1,num;
    Scanner sc=new Scanner (System.in);
    System.out.println("Enter a number - ");
    num=sc.nextInt();
    while(num>1) {
    factorial=factorial*num;
    System.out.print(num+"*");
    num=num-1;
    if(num==1)
    System.out.print(num+" = "+factorial);

    }
    }

    }

    ReplyDelete
  44. //wap to run lift from 1st floor to 5th floor 10 times with 2 sec pause
    class Lift
    {
    public static void main(String abc[])throws InterruptedException
    {
    int i=1, j=1;
    while(j<10)
    {
    while(i<=10)
    {
    if(i<=5)
    System.out.println(i);
    if(i>5)
    System.out.println(11-i);
    i++;
    Thread.sleep(200);
    }
    i=1;
    j++;
    }
    }
    }

    ReplyDelete
  45. // ADITYA BAGHEL

    // Write a programe to run lift from 1st floor to 5th floor 10 times with 2 seconds pause in each floor

    class Lift
    {
    static public void main(String ar[]) throws InterruptedException
    {
    int x=1;
    while(x<=50)
    {
    while(x<=10)
    {
    if(x<=5)
    {
    System.out.println(x);
    x++;
    }
    else
    {
    System.out.println(11-x);
    x++;
    }
    Thread t1=new Thread();
    t1.sleep(2000);
    }
    x=1;

    }


    }

    }

    ReplyDelete
  46. // ADITYA BAGHEL

    //Write a programe to calculate factorial with expression using while loop

    import java.util.*;
    class Factorial
    {
    static public void main(String ar[])
    {
    int multi=1;
    String rank="";
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    while(x>0)
    {
    multi*=x;
    if(x>1)
    rank+=x+"*";
    else
    rank+=x+"=";
    x--;
    }
    System.out.println(rank+""+multi);

    }
    }

    ReplyDelete
  47. -WAP to calculate Factorial using infinite loop with complete expression

    import java.util.Scanner;
    class Factorial
    {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter number");
    int fact=sc.nextInt();
    while(true)
    {
    if(fact==0)
    {
    System.out.print("1");
    break;
    }
    System.out.print(fact+"*");
    fact--;
    if(fact<=0)
    break;
    }
    }
    }

    ReplyDelete
  48. // ADITYA BAGHEL

    // Write a programe to run lift from 1st floor to 5th floor 10 times with 2 seconds pause in each floor

    class Lift
    {
    static public void main(String ar[]) throws InterruptedException
    {
    int x=1;
    int y=1;
    while(y<=10)
    {
    while(x<=10)
    {
    if(x<=5)
    {
    System.out.println(x);
    x++;
    }
    else
    {
    System.out.println(11-x);
    x++;
    }
    Thread t1=new Thread();
    t1.sleep(1000);
    }
    y++;
    x=1;

    }


    }

    }

    ReplyDelete
  49. //WAP to find max, second max, third max number in a pincode
    import java.util.Scanner;
    class Pincode
    {
    public static void main(String abc[])
    {
    int pincode,temp;
    int m1=0,m2=0,m3=0;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter pincode");
    pincode=sc.nextInt();
    while(pincode>0)
    {
    temp=pincode%10;
    pincode=pincode/10;
    if(temp>m1)
    m1=temp;
    else if(temp>m2)
    m2=temp;
    else if(temp>m3)
    m3=temp;
    if(pincode==0)
    break;
    }
    System.out.println( "first max "+m1+" \nsecond max "+m2+" \nthird max " +m3);
    }
    }

    ReplyDelete
  50. Program to calculate factorial with complete expression????

    /* 5*4*3*2*1=120 */

    import java.util.Scanner;
    class Factorial
    {

    public static void main(String args[])
    {
    int num,fact=1,i;
    String s="";
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number to calculate factorial");
    num = sc.nextInt();
    for(i=num;i>=1;i--)

    {
    fact = fact*i;
    if(i!=1)
    s = s+i+"*";
    else
    s = s+i;
    }

    System.out.println(s+ "= "+fact);

    }


    }

    ReplyDelete
  51. -WAP to find max, 2nd max, 3rd max number in a pincode

    import java.util.Scanner;
    class Pin
    {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter Pincode");
    int pin=sc.nextInt();
    int m1=0,m2=0,m3=0;

    while(pin>0)
    {
    int temp=pin%10;
    if(temp>m1)
    m1=temp;
    else if(temp>m2)
    m2=temp;
    else if(temp>m3)
    m3=temp;
    pin=pin/10;
    }
    System.out.println("Max no is= "+m1+ " 2nd max is= "+m2+ " 3rd max is= "+m3);
    }
    }

    ReplyDelete
  52. /*
    1 2 3 4 5
    5 4 3 2
    1 2 3
    5 4
    1
    */

    class Pattern3
    {
    public static void main(String...args)
    {
    for(int i=1;i<=5;i++)
    {
    if(i%2!=0)
    {
    for(int j=i;j<=5;j++)
    System.out.print((j-i+1)+" ");
    }
    else
    {
    for(int j=5;j>=i;j--)
    System.out.print(j+" ");
    }
    System.out.println();
    }
    }

    }

    ReplyDelete
  53. /*
    1 2 3 4 5
    5 4 3 2
    1 2 3
    5 4
    1
    */

    class Pattern3
    {
    public static void main(String...args)
    {
    for(int i=1;i<=5;i++)
    {
    if(i%2!=0)
    {
    for(int j=i;j<=5;j++)
    System.out.print((j-i+1)+" ");
    }
    else
    {
    for(int j=5;j>=i;j--)
    System.out.print(j+" ");
    }
    System.out.println();
    }
    }

    }

    ReplyDelete
  54. import java.util.Scanner;
    class Fibonacci
    {
    public static void main(String...args)
    {
    int num,t1=0,t2=1;
    Scanner sc=new Scanner(System.in);
    num=sc.nextInt();

    for(int i=0;i<=num;i++)

    {
    System.out.print(t1+" ");
    int sum = t1 + t2;
    t1 = t2;
    t2 = sum;
    }
    }

    }

    ReplyDelete
  55. //WAP to count total even and odd number in pin code using an infinite loop?
    import java.util.Scanner;
    class CountOddEven
    {
    public static void main(String...args)
    {
    int pin,odd=0,even=0,rem;
    System.out.print("Enter pincode=");
    Scanner sc=new Scanner(System.in);
    pin=sc.nextInt();
    while(pin!=0)
    {
    rem=pin%10;
    if(rem%2==0) even++;
    else odd++;
    pin/=10;
    }
    System.out.println("total number of even digits are="+even);
    System.out.println("total number of odd digits are="+odd);

    }

    }

    ReplyDelete
  56. //WAP to count total even and odd number in pin code using an infinite loop?
    import java.util.Scanner;
    class CountOddEven
    {
    public static void main(String...args)
    {
    int pin,odd=0,even=0,rem;
    System.out.print("Enter pincode=");
    Scanner sc=new Scanner(System.in);
    pin=sc.nextInt();
    while(true)
    {
    rem=pin%10;
    if(rem%2==0) even++;
    else odd++;
    pin/=10;
    if(pin==0)
    break;
    }
    System.out.println("total number of even digits are="+even);
    System.out.println("total number of odd digits are="+odd);

    }

    }

    ReplyDelete
  57. // WAP to print the below pattern

    A B C D E
    a b c d
    A B C
    a b
    A


    import java.util.Scanner;
    public class Main {

    public static void main(String[] abc) {
    int i,j;
    char ch;
    for(i=5;i>0;i--) {
    ch='A';
    for(j=1;j<=i;j++) {
    if(i%2==1)
    System.out.print(ch +" ");
    else
    System.out.print((char)(ch+32) +" ");
    ch++;
    }System.out.println();
    }


    }

    }

    ReplyDelete
  58. // WAP to print the below pattern
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5

    import java.util.Scanner;
    public class Main {

    public static void main(String[] abc) {
    int i,j;
    for(i=1;i<=5;i++) {
    for(j=1;j<=i;j++) {
    System.out.print(j+" ");
    }System.out.println();
    }


    }

    }



    ReplyDelete

  59. // table
    Pushpendra sisodiya

    import java.util.Scanner;
    class Table
    {
    public static void main(String args[])
    {
    int n,i,s;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter num ");
    n=sc.nextInt();
    for(i=1;i<=10;i++)
    {
    s=n*i;
    System.out.println(s);
    }


    }

    }

    ReplyDelete
  60. // Pushpendra Sisodiya


    *
    **
    ***
    ****
    *****
    import java.util.Scanner;
    class Pattern
    {
    public static void main(String args[])
    {
    int num,i,j;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter any number");
    num=sc.nextInt();
    for(i=1;i<=num;i++)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print("*");
    }
    }

    System.out.println();

    }

    }

    ReplyDelete
  61. // Pushpendra Sisodiya
    program
    12345
    1234
    123
    12
    1

    import java.util.Scanner;
    class Pattern1
    {
    public static void main(String args[])
    {
    int i,j,n;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter value of n");
    n=sc.nextInt();
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n-i;j++)
    {
    System.out.print(j);

    }
    System.out.println();
    }

    }

    }

    ReplyDelete
  62. // WAP to print the below pattern
    1 0 0 1 0
    1 0 0 1
    1 0 0
    1 0
    1
    import java.util.Scanner;
    public class Main {

    public static void main(String[] abc) {
    int i,j;
    for(i=1;i<=5;i++) {
    for(j=1;j<=6-i;j++) {
    if(j==1||(j==4)) {
    System.out.print("1 ");
    }
    else
    System.out.print("0 ");
    }System.out.println();
    }


    }

    }



    ReplyDelete
  63. // WAP to print the below pattern
    A a B b C
    A a B b
    A a B
    A a
    A

    import java.util.Scanner;
    public class Main {

    public static void main(String[] abc) {
    int i,j;
    char ch;
    for(i=1;i<=5;i++) {
    ch='A';
    for(j=1;j<=6-i;j++) {
    if(j%2==1) {
    System.out.print(ch+" ");
    }
    else {
    System.out.print(((char)(ch+32))+" ");
    ch++;
    }
    }System.out.println();
    }


    }

    }

    ReplyDelete
  64. kinjal singh sirohiFebruary 9, 2021 at 9:31 PM

    //Write a program to calculate factorial of any entered number?
    import java.util.Scanner;
    class Factorial
    {
    public static void main(String args[])
    {
    int num,i,a=1;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter num");
    num=sc.nextInt();

    for(i=num;i>=1;i--)
    {
    a=a*i;
    }
    System.out.println(a);
    }
    }

    ReplyDelete
  65. display prime pattern?
    class Prime
    {

    public static void main(String args[])
    {
    int start=2;
    int end=29;
    int i,j,c=0,l=0;
    for(i=2;i<=29;i++)
    {
    for(j=2;j<i;j++)
    {
    l++;
    if(i%j==0)
    {
    break;
    }
    }
    if(i==j)
    {
    System.out.print(i + " ");
    c++;
    if(c==1 || c==3 || c==6)
    System.out.println();

    }

    }
    System.out.println("Total steps"+ (i*l));
    }
    }

    ReplyDelete
  66. /*
    12345
    1234
    123
    12
    1
    */
    class Pattern
    {
    public static void main(String[] args) {

    int i,j;
    for(i=5;i>=1;i--)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  67. // lift program
    class Pattern1
    {
    public static void main(String[] args) throws InterruptedException {
    int i=1;
    for(i=1;i<=10;i++)
    {
    if(i<=5)
    {


    System.out.println(i);
    Thread.sleep(2000);
    }
    else
    {
    System.out.println(11-i);
    Thread.sleep(2000);


    }


    }
    }
    }

    ReplyDelete
  68. /*
    ABCDE
    ABCD
    ABC
    AB
    A
    */
    class Pattern3
    {
    public static void main(String[] args) {

    int i,j;
    for(i=5;i>=1;i--)
    {

    char ch='A';
    for(j=1;j<=i;j++)
    {
    System.out.print(ch);
    ch++;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  69. /*
    A B C D E
    a b c d
    A B C
    a b
    A
    */
    class Pattern4
    {
    public static void main(String[] args) {

    int i,j;
    for(i=5;i>=1;i--)
    {

    char ch='A';
    for(j=1;j<=i;j++)
    {
    if(i%2!=0)
    {
    System.out.print(ch + " ");
    ch++;
    }
    else
    {
    System.out.print((char)(32+ch) +" ");
    ch++;
    }
    }



    System.out.println();
    }
    }
    }

    ReplyDelete
  70. /*
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    */
    class Pattern5
    {
    public static void main(String[] args) {

    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  71. /*
    A a B b C
    A a B b
    A a B
    A a
    A
    */
    class Pattern7
    {
    public static void main(String[] args)
    {

    int i,j;
    for(i=5;i>=1;i--)
    {
    char ch='A';
    for(j=1;j<=i;j++)
    {
    if(j%2!=0)
    {
    System.out.print(ch +" ");
    ch++;

    }
    else
    System.out.print((char)(ch+32)+ " ");

    }

    System.out.println();
    }
    }
    }

    ReplyDelete
  72. /*
    1 2 3 4 5
    5 4 3 2
    1 2 3
    5 4
    1
    */
    class Pattern8
    {
    public static void main(String[] args) {

    int i,j;
    for(i=5;i>=1;i--)
    {
    for(j=1;j<=i;j++)
    {
    if(i%2!=0)
    System.out.print(j);
    else
    System.out.print(6-j);
    }

    System.out.println();
    }
    }
    }

    ReplyDelete
  73. //1
    //1 2
    //1 2 3
    //1 2 3 4
    //1 2 3 4 5

    class Pattern10
    {
    public static void main(String args[])
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(j+"");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  74. /*1 0 0 1 0
    1 0 0 1
    1 0 0
    1 0
    1*/
    class Pattern11
    {
    public static void main (String args[])
    {
    int i,j,a=1,b=0;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=6-i;j++)
    {
    if(j==1||j==4) {
    System.out.print(a+"");
    }
    else {
    System.out.print(b+"");

    }
    }System.out.println();
    }
    }
    }

    ReplyDelete
  75. // WAP to print the below pattern

    *
    * * *
    * * * * *
    * * * * * * *
    * * * * * * * * *
    * * * * * * *
    * * * * *
    * * *
    *

    import java.util.Scanner;
    public class Main {

    public static void main(String[] abc) {
    int i,j;
    for(i=1;i<=9;i++) {
    if(i<6) {

    for(j=5;j>0;j--) {
    if(j>i)
    System.out.print(" ");
    else
    System.out.print("* ");
    }

    for(j=1;j=j)
    System.out.print(" ");
    else
    System.out.print("* ");
    }
    for(j=4;j>0;j--) {
    if(j>i-5)
    System.out.print("* ");

    }
    }
    System.out.println();
    }


    }

    }


    ReplyDelete
  76. // WAP to calculate the sum of one digit positive number?
    Output: Sum of one digit numbers is - 45

    public class Main {

    public static void main(String[] abc) {
    int i,num=0;
    for(i=1;i<10;i++) {
    num=num+i;
    }
    System.out.print("Sum of one digit numbers is - "+num);
    }

    }

    ReplyDelete
  77. WAP to print Fibonacci series?

    0,1,1,2,3,5,8,13

    import java.util.Scanner;
    public class Main {
    static int n;
    public static void main(String[] args) {

    Scanner scan=new Scanner(System.in);
    System.out.print("Enter a numbwer of terms to be in Fibbonaci series - ");
    n=scan.nextInt();
    int fibbo=0,fibbo1=0,fibbo2=1;
    System.out.print(fibbo1+" "+fibbo2);
    for(int i=1;i<n;i++) {
    fibbo=fibbo1+fibbo2;
    fibbo1=fibbo2;
    fibbo2=fibbo;
    System.out.print(" "+fibbo);
    }
    }

    }

    ReplyDelete
  78. WAP to print A to Z using a while loop?
    public class Main {
    public static void main(String[] args) {

    char ch='A';
    while(ch<91) {

    System.out.print(ch+" ");
    ch++;
    }
    }

    }

    ReplyDelete
  79. WAP to count total even and odd number in pin code using an infinite loop?
    Program:

    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {

    int pincode=0,even=0,odd=0;
    boolean b=true;
    Scanner scan=new Scanner(System.in);
    System.out.print("Enter pincode - ");
    pincode=scan.nextInt();
    while(b) {
    if(pincode%2==0) {
    even++;
    }
    else {
    odd++;
    }
    pincode=pincode/10;
    if(pincode==0)
    b=false;
    }
    System.out.print("Even numbers in pincode are - "+even+"\nOdd numbers in pincode are- "+odd);
    }

    }

    ReplyDelete
  80. A B C D E
    B C D E
    C D E
    D E
    E
    Program:
    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    int i,j;
    char ch='A';
    for(i=0;i<5;) {
    for(j=1;j<=5;j++) {
    if(i>=j)
    System.out.print(" ");
    else {
    System.out.print(ch+" ");
    ch++;
    }

    }System.out.println();
    i++;
    ch='A';
    ch=(char)(ch+i);
    }
    }

    }


    ReplyDelete
  81. kinjal singh sirohiFebruary 12, 2021 at 7:37 PM

    //WAP to calculate the sum of one digit positive number?
    import java.util.Scanner;
    class Sumofdigit
    {
    public static void main (String args[])
    {
    int m, n, sum = 0;
    Scanner s = new Scanner(System.in);
    System.out.print("Enter the number:");
    m = s.nextInt();
    while(m > 0)
    {
    n = m % 10;
    sum = sum + n;
    m = m / 10;
    }
    System.out.println("Sum of Digits:"+sum);
    }
    }

    ReplyDelete
  82. kinjal singh sirohiFebruary 13, 2021 at 7:28 PM

    //WAP to print A to Z using a while loop?

    class Printatoz
    {
    public static void main(String[] args)
    {

    char ch='A';
    while(ch<91)
    {

    System.out.print(ch+" ");
    ch++;
    }
    }

    }

    ReplyDelete
  83. //Wap to calculate Factorial with complete Expression
    import java.util.Scanner;
    class Factorial
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter the Number");
    int a = sc.nextInt();
    long fact = 1;
    int i = 1;
    while(i<=a)
    {
    fact = fact * i;
    i++;
    }
    int j=1;
    while(j<=a)
    {


    System.out.print(j+"*");
    j++;

    }
    System.out.println("="+fact);
    }
    }

    ReplyDelete
  84. WAP to find max and second max number?
    class ReverseExample
    {

    public static void main(String args[])
    {
    int num=487;
    int r=0,r1=0,rem=0;
    while(num!=0) // 0!=0
    {
    rem = num%10; // 4
    if(r<rem) //8<4
    {
    r1=r; //r1=7
    r=rem; // r=8
    }
    else if(r1<rem) //7<4
    {
    r1=rem;
    }
    num = num/10; // 0

    }
    System.out.println("Max"+r+ " Second Max"+ r1);
    }


    }

    ReplyDelete
  85. //WAP to find largest nd 2nd largest no in digit
    import java.util.Scanner;
    class Large
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Number");
    String s = sc.next();
    long a =Long.parseLong(s);
    long l = 0;
    long r = 0;
    long sl=0;
    while(a>0)
    {
    r = a%10;
    if(l=sl)
    sl = r;
    a=a/10;
    }
    System.out.println("The largest number is"+" "+l);
    System.out.println("The Second largest number is"+" "+sl);
    }
    }

    ReplyDelete
  86. //WAP to print A to Z and a to z
    class Alpha
    {
    public static void main (String args[])
    {
    int i =65;
    int j =97;
    char ch;
    char ce;
    while(i<91)
    {
    ch=(char)i;
    System.out.println(ch);
    i++;
    }
    while(j<123)
    {
    ce=(char)j;
    System.out.println(ce);
    j++;
    }
    }
    }

    ReplyDelete
  87. //Sum of two digit odd and even number
    import java.util.Scanner;
    class SumOE
    {
    public static void main(String args[])
    {
    int i=10;
    int se = 0;
    int so = 0;
    while(i<100)
    {
    if(i%2==0)
    se = se+i;
    else
    so+=i;
    i++;

    }
    System.out.println("Sum of even two digit no :"+se);
    System.out.println("Sum of Odd two digit no :"+so);
    }
    }

    ReplyDelete
  88. //WAP to reverse a number
    import java.util.Scanner;
    class Reverse
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Number :");
    int n = sc.nextInt();
    int rev = 0;
    System.out.println("Orignal Number :"+n);

    while(n>0)
    {
    rev = rev*10+n%10;
    n = n/10;
    }
    System.out.println("Reverse number :"+rev);
    }
    }

    ReplyDelete
  89. //WAP to perform factorial when even and tables when odd
    import java.util.Scanner;
    class Loop
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Number :");
    long n = sc.nextLong();
    int i = 1;
    long s =1;
    while(i<=n)
    {
    if(n%2==0)
    {
    //System.out.println("Given number is even so we print Factorial");
    s = s*i;
    i++;
    System.out.println(s);

    }
    else
    {
    //System.out.println("Given number is odd so we print table");
    while(i<11)
    {
    s = n*i;
    i++;
    System.out.println(s);
    }

    }

    }
    }

    }

    ReplyDelete
  90. //To find the Largest and Second largest digit From any number
    class Ex
    {
    public static void main(String args[])
    {
    int n=1830296547;int Largest=0;int Second_Largest=0;int rem=0;
    while(n>0)
    {
    rem=n%10;
    if(Largest<rem)
    {
    Second_Largest=Largest;
    Largest=rem;
    }
    else if(Second_Largest<=rem)
    Second_Largest=rem;
    n=n/10;
    }
    System.out.println("Largest Digit=" +Largest);
    System.out.println("Second_Largest Digit=" +Second_Largest);



    }


    }

    ReplyDelete
  91. WAP to find max and second max

    class Maxmobile
    {
    public static void main(String args[])
    {
    int mobile = 678912345,num;
    int max=0,smax=0;
    while(mobile!=0)
    {
    num = mobile%10;
    if(max<num)
    {
    smax=max;
    max=num;
    }
    else if(smax<num)
    {
    smax=num;
    }

    mobile = mobile/10;

    }

    System.out.println(max +" "+smax);


    }



    }

    ReplyDelete
  92. //Wap to perform factorial when number is even and table when number is odd
    import java.util.Scanner;
    class FactOE
    {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter the number:");
    int n=sc.nextInt();
    int i=1,fact=1,t=1;
    while(i<=n)
    {
    if(n%2==0)
    {
    fact=fact *i;
    i++;
    System.out.println(fact);


    }
    else
    {
    while(i<=10)
    {
    t=n*i;
    System.out.println(+t);
    i++;
    }
    }
    }
    }

    }

    ReplyDelete
  93. class EsumOsum
    {
    public static void main(String args[])
    {
    int n=10;
    int Osum=0;
    int Esum=0;
    while(n<100)
    {
    if(n%2==0)
    Esum+=n;
    else
    Osum+=n;
    n++;
    }
    System.out.println("Esum=" +Esum);
    System.out.println("Osum=" +Osum);

    }

    }

    ReplyDelete
  94. //program to display A to Z and a to z in a single while loop
    class A1
    {
    public static void main(String args[])
    {
    int i=65;
    char small;
    char capital;

    while(i<123)
    {

    if(i>64 && i<91)
    {
    capital=(char)i;
    i++;
    System.out.println(capital);
    }
    else if(i>96 && i<123)
    {
    small=(char)i;
    i++;
    System.out.println(small);
    }
    else
    i++;
    }




    }
    }

    ReplyDelete
  95. //program to display A to Z and a to z in a single while loop
    class A1
    {
    public static void main(String args[])
    {
    int i=65;
    char small;
    char capital;

    while(i<123)
    {

    if(i>64 && i<91)
    {
    capital=(char)i;
    i++;
    System.out.println(capital);
    }
    else if(i>96 && i<123)
    {
    small=(char)i;
    i++;
    System.out.println(small);
    }
    else
    i++;
    }




    }
    }

    ReplyDelete
  96. //program to display A to Z and a to z in for loop
    class A2z
    {
    public static void main(String args[])
    {
    int i=65;
    char small;
    char capital;

    for(i=65;i<123;i++)
    {

    if(i>64 && i<91)
    {
    capital=(char)i;

    System.out.println(capital);
    }
    else if(i>96 && i<123)
    {
    small=(char)i;

    System.out.println(small);
    }
    else
    i++;
    }




    }
    }

    ReplyDelete
  97. package loops;
    import java.util.Scanner;
    public class Factorial {

    public static void main(String[] args) {
    int n,i,f=1;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the number");
    n=sc.nextInt();

    i=1;

    while(i<=n)
    {
    f=(f*i);
    i++;


    }

    System.out.println(n+"!"+"="+f);
    sc.close();
    }

    }

    ReplyDelete
  98. import java.util.Scanner;
    class prime{
    public static void main(String args[])
    {
    Scanner se = new Scanner(System.in);
    System.out.println("ENTER NUMBER TO CHECK IT IS PRIME OR NOT:- ");
    int num = se.nextInt();
    int i=1, res=0;
    String result;
    while(i<=num)
    {
    if(num%i==0)
    res++;
    i++;
    }
    if (res==2)
    result="ENTRED NUMBER IS PRIME";
    else
    result="ENTRED NUMBER IS NOT PRIME";
    System.out.println(result);
    }
    }

    ReplyDelete
  99. import java.util.Scanner;
    class factorial
    {
    public static void main(String args[])
    {
    int num,i=1,f=1;
    Scanner sc = new Scanner(System.in);
    System.out.println("ENTER NUMBER TO FINF FACTORIAL:- ");
    num=sc.nextInt();
    while(i<=num)
    {
    f=f*i;
    i++;
    }
    System.out.println("RESULT IS:- "+f);
    }
    }

    ReplyDelete
  100. class sumwhile{
    public static void main(String args[])
    {
    int i=1, res=0;
    while(i<10)
    {
    res=res+i;
    ++i;
    }
    System.out.println("SUM OF ALL ONE DIGIT NUMBERS ARE:- "+res);
    }
    }

    ReplyDelete
  101. import java.util.Scanner;
    class reversewhile{
    public static void main(String args[])
    {
    Scanner se = new Scanner(System.in);
    System.out.println("ENTER PIN CODE TO REVERSE IT:- ");
    int num = se.nextInt();
    int res=0;
    while(num!=0)
    {
    res=res*10;
    res=res+(num%10);
    num=num/10;
    }
    System.out.println("REVERSED PIN CODE IS:- "+res);
    }
    }

    ReplyDelete
  102. public class SumOfPositiveNum {

    public static void main(String[] args) {
    int i=1,sum=0;
    while(i<10)
    {
    sum=sum+i;
    i++;

    }
    System.out.println("Sum = "+sum);
    }

    }

    ReplyDelete
  103. package loops;
    import java.util.Scanner;
    public class CheckPrimeNum {

    public static void main(String[] args) {
    int i=1, res=0,num;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number ");
    num = sc.nextInt();
    String result;
    while(i<=num)
    {
    if(num%i==0)
    res++;
    i++;
    }
    if (res==2)
    {
    result="Number is Prime";
    }
    else
    {
    result="Number is not prime";
    }
    System.out.println(result);
    sc.close();
    }

    }

    ReplyDelete
  104. # wap to display star pattern using Java

    class SeriesDemo
    {
    public static void main(String args[])
    {
    int i,j,c=0,space=0,star=2;
    for(i=1;i<=5;i++)
    {
    if(i<4)
    {
    for(c=2;c>=i;c--)
    {
    System.out.print(" ");
    }
    for(j=2;j<2*i+1;j++)
    {
    System.out.print("*");
    }
    }
    else
    {
    for(c=0;c<=space;c++)
    {
    System.out.print(" ");
    }
    for(j=1;j<=2*star-1;j++)
    {
    System.out.print("*");
    }
    space++;
    star--;
    }
    System.out.println();


    }


    }




    }

    ReplyDelete






  105. Ankita Verma

    class NesClass
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  106. Ankita Verma
    class NesClass
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  107. Ankita Verma
    class NesClass
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  108. Ankita Verma
    class NesClass
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  109. Ankita Verma
    class NesClass
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete


  110. Ankita Verma
    class NesClass
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete

  111. Ankita Verma
    class NesClass
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete






  112. Ankita Verma
    class Loop
    {
    public static void main(String[]arg)
    {
    for(int j=5; j>=1; j--)
    {
    for(int i=1; i<=j; i++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  113. Ankita Verma
    import java.util.Scanner;
    class OddEv
    {
    public static void main(String args[])
    {
    int num=2;
    int i=1;
    Scanner sc =new Scanner(System.in);
    System.out.println("enter the pin number");
    num=sc.nextInt();
    while(i<=num)
    {
    i++;
    }

    if(num%2==0)
    System.out.println("even");
    else
    System.out.println("odd");

    }
    }

    ReplyDelete
  114. Ankita Verma

    import java.util.Scanner;
    public class PinMax
    {

    public static void main(String[] args)
    {
    int p,max1=0,max2=0,max3=0,c;
    Scanner scan=new Scanner(System.in);
    System.out.print("Enter pincode - ");
    p=scan.nextInt();
    while(true) {
    c=p%10;
    p/=10;
    if(c>max1)
    max1=c;
    else if(c>max2)
    max2=c;
    else if(c>max3)
    max3=c;
    if(p==0)
    break;
    }
    System.out.print("maximum - "+max1+"\nSecond Maximum - "+max2+"\nthird maximum - "+max3);
    }
    }

    ReplyDelete






  115. Ankita Verma
    import java.util.Scanner;

    public class Revpin
    {

    public static void main(String[] args)
    {
    int num=0;
    int renum=0;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter number");
    num= sc.nextInt();

    while( num != 0 )
    {
    renum= renum*10;
    renum= renum+num%2;
    num =num/10;
    System.out.println(" " + num);
    }
    }

    }

    ReplyDelete
    Replies
    1. Sandeep kelwa

      import java.util.Scanner;
      class Prime
      {
      public static void main(String args[])
      {
      int n,c=0,i;
      System.out.println("Enter your number");
      Scanner sc= new Scanner(System.in);
      n = sc.nextInt();
      for(i=1; i<=n; i++)
      {
      if(n%i==0)
      {
      c++;
      }
      }
      if(c==2)
      System.out.println("its prime number");
      else
      System.out.println("its not prime number");
      }
      }






      Delete
    2. Sandeep kelwa

      import java.util.Scanner;
      class Prime
      {
      public static void main(String args[])
      {
      int n,c=0,i;
      System.out.println("Enter your number");
      Scanner sc= new Scanner(System.in);
      n = sc.nextInt();
      for(i=1; i<=n; i++)
      {
      if(n%i==0)
      {
      c++;
      }
      }
      if(c==2)
      System.out.println("its prime number");
      else
      System.out.println("its not prime number");
      }
      }






      Delete
    3. Sandeep kelwa

      class AZ
      {
      public static void main(String args[])
      {
      char Character ='A';
      while(Character<='z')
      {
      System.out.println(Character +"");
      Character++;
      }
      }
      }

      Delete
  116. Sandeep kelwa

    import java.util.Scanner;
    class Fact
    {
    public static void main(String args[])
    {
    int num,i,f=1;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number for table");
    num=sc.nextInt();

    for(i=1;i<=num;i++)
    {
    f=f*i; #f = 120

    }
    System.out.println("result is "+f);


    }
    }

    ReplyDelete
  117. #Program to print following pattern
    1 2 3 4 5
    2 3 4 5
    3 4 5
    4 5
    5


    class NestedLoop
    {
    public static void main(String args[])
    {
    for(int i=1;i<=5;i++)
    {
    int c=1;
    for(int k=1;k<i;k++)
    {
    System.out.print(" ");
    c++;
    }
    for(int j=1;j<=6-i;j++)
    {
    System.out.print(c);
    c++;
    }

    System.out.println();

    }

    }

    }

    ReplyDelete
  118. Print Pyramid Matrix?



    class NestedLoop
    {
    public static void main(String args[])
    {
    int n=10;
    for(int i=0;ii;k--)
    {
    System.out.print(" ");

    }
    for(int j=1;j<=2*i+1;j++)
    {
    System.out.print("*");

    }

    System.out.println();

    }

    }

    }

    ReplyDelete
  119. #Solve Following Pattern

    A a B b C
    A a B b
    A a B
    A a
    A


    class NestedLoop
    {
    public static void main(String args[])
    {

    for(int i=1;i<=5;i++)
    {
    int ch=65;
    for(int j=1;j<=6-i;j++)
    {
    if(j%2!=0)
    {
    System.out.print((char)ch);
    }
    else
    {
    System.out.print((char)(ch+32));
    ch=ch+1;
    }

    }

    System.out.println();

    }

    }

    }

    ReplyDelete
  120. // yogesh seroke
    // sum of single digit num
    WAP to calculate the sum of one digit positive number?
    import java.util.Scanner;

    public class DigitSum {

    public static void main(String[] args) {
    int m,n,sum = 0;
    Scanner sc =new Scanner(System.in);
    System.out.println("enter number");
    m =sc.nextInt();
    while(m>0)
    {
    n=m%10;
    sum=sum+n;m=m/10;

    }
    System.out.println("sum of digit" + sum);


    }

    }

    ReplyDelete
  121. //yogesh seroke
    //table
    import java.util.Scanner;
    class table
    {
    public static void main(String[]arg)
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter num");
    int num=sc.nextInt();

    int i=0;
    while(i<=10)
    {
    System.out.println(num+"*"+i+"="+(num*i));
    i++;
    }
    System.out.println("total step of i"+i);
    }
    }

    ReplyDelete
  122. //yogesh seroke
    //factorial
    import java.util.Scanner;
    class fact
    {
    public static void main(String[]arg)
    {
    int f=1;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the value");
    int num=sc.nextInt();

    for(int i=1; i<=num; i++)
    {
    f=f*i;
    System.out.println(f);
    }
    }
    }

    ReplyDelete
  123. //yogesh seroke
    //prime
    class Checkprime
    {

    public static void main(String args[])
    {
    int num=6,c=0;
    int i=1;
    while(i<=num)
    {
    if(num%i==0)
    c++;
    i++;


    }

    if(c==2)
    System.out.println("prime");
    else
    System.out.println("not prime");


    }

    }

    ReplyDelete
  124. //yogesh seroke
    //maximum in pincode
    import java.util.Scanner;
    public class PinMax
    {

    public static void main(String[] args)
    {
    int p,max1=0,max2=0,max3=0,c;
    Scanner scan=new Scanner(System.in);
    System.out.print("Enter pincode - ");
    p=scan.nextInt();
    while(true) {
    c=p%10;
    p/=10;
    if(c>max1)
    max1=c;
    else if(c>max2)
    max2=c;
    else if(c>max3)
    max3=c;
    if(p==0)
    break;
    }
    System.out.print("maximum - "+max1) ;
    }
    }

    ReplyDelete
  125. //yogesh seroke
    //fibonacci series
    class Fibonacciseries
    {
    public static void main(String[]arg)
    {
    int a=0, b=1,c;

    for(int i=1; i<=10; i++)
    {
    c=a+b;
    System.out.println(c);
    a=b;
    b=c;
    }
    }
    }

    ReplyDelete
  126. //yogesh seroke
    //WAP to print A to Z using a while loop?

    public class Alphabets {

    public static void main(String[] args) {
    char t='a';
    while(t<='z')
    {
    System.out.println(t);
    t++;
    }

    }
    }

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post