Sunday, 13 September 2020

Java Programming in BlueJ IDE

 1.



public class even

{

    public static void main(String args[])

    {

        int a;

        System.out.println("Even Numbers From 1 to 10 :");

        for(a=2;a<=10;a=a+2)

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

    }

}




2.





public class odd

{

    public static void main(String args[])

    {

        int a;

        System.out.println("odd numbers from 1 to 10");

        for(a=1;a<=10;a=a+2)

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

    }

}







        

3.




public class program1
{
    public static void main(String args[])
    {
        int a;
        System.out.println("Natural numbers from 1 to 10");
        for(a=1;a<=10;a++)        
        System.out.println(a+" ");        
        
    }
}
        




4.



public class program2
{
    public static void main(String args[])
    {
        int a=1;
        System.out.println("Natural numbers from 1 to 10");
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        a=a+1;
        System.out.println(a+" ");
        
    }
}
        





5.




public class seriers1
{
    public static void main(String args[])
    {
        int a;
        System.out.println("numbers from 1 to 20");
        for(a=1;a<20;a=a+3)
        System.out.print(a+" ");
    }
}
        










6.




public class series2
{
    public static void main(String args[])
    {
        int a;
        System.out.println("square numbers from 1 to 10");
        for(a=1;a<=10;a=a+1)
        System.out.print(a*a+" ");
    }
}
        



7.



public class series3
{
    public static void main(String args[])
    {
        int a;
        System.out.println("cube numbers from 1 to 10");
        for(a=1;a<=10;a=a+1)
        System.out.print(a*a*a+" ");
    }
}
        




8.



class cal
{
    public static void main()
    {
        int p=560;
        double total;
        total=p*3;
        System.out.println("one book price is "+p);
        System.out.println("total price of 3 books is "+total);
        
    }
}




9.


public class prog1
{
    public static void main(String args[])
    {
        int a=15,b=25;
        int sum=0;
        sum=a+b;
        System.out.println("The Number A is : "+ a);
        System.out.println("The Number B is : "+ b);
        System.out.println("The summation of a and b is : "+ sum);
        
    }
}
        


10.



public class prog2
{
    public static void main(String args[])
    {
        int a=5;
        int b=8;
        int c=6;
        int m=a*b*c;
        System.out.println("The Number A is : "+ a);
        System.out.println("The Number B is : "+ b);
        System.out.println("The Number C is : "+ c);
        System.out.println("The multiply of a,b,c is : "+ m);
        
    }
}
        




11.




public class prog3
{
    public static void main(String args[])
    {
        int a=55,b=25,d;
        d=a-b;
        System.out.println("The Number A is : "+ a);
        System.out.println("The Number B is : "+ b);
        System.out.println("The Difference of a and b is : "+ d);
        
    }
}
        



12.





public class prog4
{
    public static void main(String args[])
    {
        int x=31,y=2,q,r;
        q=x/y;
        r=x%y;        
        System.out.println("The Number x is : "+ x);
        System.out.println("The Number y is : "+ y);
        System.out.println("The quotient : "+ q);
        System.out.println("The remainder : "+ r);
        
    }
}
        

        


Friday, 29 May 2020

C++ Loops - while, for and do while loop


C++ Loops - while, for and do while loop


In any programming language, loops are used to execute a set of statements repeatedly until a particular condition is satisfied.


How it works
A sequence of statement is executed until a specified condition is true. This sequence of statement to be executed is kept inside the curly braces { } known as loop body. After every execution of loop body, condition is checked, and if it is found to be true the loop body is executed again. When condition check comes out to be false, the loop body will not be executed.


There are 3 type of loops in C++ language
while loop
for loop
do-while loop


while loop
while loop can be address as an entry control loop. It is completed in 3 steps.
·         Variable initialization.(e.g int x=0;)
·         condition(e.g while( x<=10))
·         Variable increment or decrement (x++ or x-- or x=x+2)
Syntax:
 
variable initialization;
while (condition)
{
    statements;
    variable increment or decrement; 
}
 


for loop
for loop is used to execute a set of statement repeatedly until a particular condition is satisfied. we can say it an open ended loop. General format is,
 
for(initialization; condition; increment/decrement)
{
    statement-block;
}
-block;
}
In for loop we have exactly two semicolons, one after initialization and second after condition. In this loop we can have more than one initialization or increment/decrement, separated using comma operator. for loop can have only one condition.


do...while loop

In some situations it is necessary to execute body of the loop before testing the condition. Such situations can be handled with the help of do-while loop. do statement evaluates the body of the loop first and at the end, the condition is checked using while statement. General format of do-while loop is,

 
do
{
    // a couple of statements
}
while(condition);
 


Jumping out of a loop

Sometimes, while executing a loop, it becomes necessary to skip a part of the loop or to leave the loop as soon as certain condition becocmes true, that is jump out of loop. C language allows jumping from one statement to another within a loop as well as jumping out of the loop.

1) break statement

When break statement is encountered inside a loop, the loop is immediately exited and the program continues with the statement immediately following the loop.

2) continue statement

It causes the control to go directly to the test-condition and then continue the loop process. On encountering continue, cursor leave the current cycle of loop, and starts with the next cycle.

Class XI Computer Application Wbchse

 Class XI Computer Application Wbchse