Java Basic Programs For Biginners | Brothers Study Zone

Q.1:-WAP IN JAVA TO ADD TWO NUMBERS.

public class Add{

public static void main(String args[]){

int a=25;

int b=01;

int c=a+b;

System.out.println("value of a=25");

System.out.println("value of b=01");

System.out.println("value of c=a+b then"+c);

}

}

OUTPUT:-

Q.2:-WAP IN JAVA TO ADD SOME NUMBERS USING ARRAY.

public class Array{

public static void main(String args[]){

double result=0;int i;

double num1[]={10.1,11.1,12.1,13.1,14.1,15.1};

for(i=0;i<5;i++)

{

result=result+num1[i];

}

System.out.println("the avg is="+result/5);

}

}

OUTPUT:-

Q.3:-WAP IN JAVA TO DISPLAY BOOLEAN CONDITION.

 public class Boolean{

public static void main(String args[]){

boolean b=false;

System.out.println("b is ="+b);

b= true;

System.out.println("b is ="+b);

if(b)

System.out.println("this is executed");

b=false;if(b)

System.out.println("this is not  executed");

}

}

OUTPUT:-

Q.4:-WAP IN JAVA TO FIND FORMULA OF VOLUME.

class Box{

double width;

double height;

double depth;

}

class Boxsample{

public static void main(String args[]){

Box b1=new Box();

Box b2=new Box();

double vol;

b1.width=10;

b1.height=20;

b1.depth=15;

b2.width=10;

b2.height=20;

b2.depth=15;

vol=b1.width*b1.height*b1.depth;

System.out.println("the value is="+vol);

vol=b2.width* b2.height*b2.depth;

System.out.println("the value is="+vol);

}

}

OUTPUT:-

Q.5:-WAP IN JAVA TO DISPLAY SOME STRING VALUE USING BREAK CONDION.

public class Breaks{

public static void main(String args[]){

boolean t=true;

first:{

           second:{

                third:{

                                System.out.println("before the break...");

                                if(t) break second;

                                System.out.println("this won't executed...");

                }

                System.out.println("this won't executed...");

                }

                System.out.println("this is after second break...");

}

}

}

OUTPUT:-

Q.6:-WAP IN JAVA TO DISPLAY CHAR VALUE.

public class Char{

public static void main(String args[]){

char ch1,ch2;

ch1=88;

ch2='Y';

System.out.print("ch1  and  ch2=");

System.out.print(ch1+" "+ch2);

}

}

OUTPUT:-

Q.7:-WAP IN JAVA TO DISPLAY 1 TO 10 USING CONTINUE.

public class Cont{

public static void main(String args[]){

int i=1;

for(i=0;i<10;i++)

                if(i==5)

                continue;

System.out.println("i= "+i);

}

}

OUTPUT:-

Q.8:-

public class Continue{

public static void main(String args[]){

int i;

for(i=0;i<10;i++)

{

if(i==5)

continue;

System.out.println(" i= "+i);

}

System.out.println("   ");

}

}

OUTPUT:-

Q.9:-WAP IN JAVA TO ADD 5 NOS AND FIND AVG VALUE.

public class Dum{

public static void main(String args[]){

int a=45;

int b=66;

int c=60;

int d=66;

int e=88;

int f=68;

System.out.println("value of a=45");

System.out.println("value of b=66");

System.out.println("value of c=60");

System.out.println("value of d=66");

System.out.println("value of e=88");

int sum=a+b+c+d+e;

System.out.println("value of sum ="+sum);

int avg=sum/5;

System.out.println("value of avg ="+avg);

 

}

}

OUTPUT:-

Q.10:-WAP IN JAVA TO DISPLAY 1 TO 09.

public class F{

                public static void main(String args[]){

int s;

for(s=1; s<10; s++)

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

}

}

OUTPUT:-

Q.11:-WAP IN JAVA TO FIND FORMULA OF VOLUME.

class Fox{

double width;

double height;

double depth;

double volume(double width,double height,double depth)

{

                return(width*height*depth);

}

}

class Foxsample{

public static void main(String args[]){

Fox b1=new Fox();

double vol=b1.volume(10,20,15);

System.out.println("this is vol="+vol);

}

}

OUTPUT:-

 

Q.12:-WAP IN JAVA TO FIND INTEREST.

public class Inc{

public static void main(String args[]){

int p=5200;

int r=3;

int t=2;

int si=p*r*t/100;

System.out.print("value of S.I="+si );

System.out.print("only");

}

}

OUTPUT:-

Q.13:-WAP IN JAVA TO DISPLAY INCREMENT OPERATOR.

public class Incdec{

public static void main(String args[]){

int a=1;

int b=2;

int c;

int d;

c=++b;

d=a++;

c++;

System.out.println("a="+a);

System.out.println("b="+b);

System.out.println("c="+c);

System.out.println("d="+d);

}

}

OUTPUT:-

Q.14:-WAP IN JAVA TO ADD TWO NO USING  METHOD OVERLOADING.

class razi

{

int a=10;

int sum;

void add()

{

sum=a+50;

System.out.println(+sum);

}

void add(int x)

{

sum=a+x;

System.out.println(+sum);

}

void add(int x,int y)

{

sum=x+y;

System.out.println(+sum);

}

}

class Main

{

public static void main(String args[])

{

razi ob=new razi();

ob.add(50,200);

ob.add(200);

ob.add();

}

}

OUTPUT:-

Q.15:-WAP IN JAVA TO DISPLAY MODULAR OPERATOR.

public class Module{

public static void main(String args[]){

int x=42;

double y=42.25;

System.out.println(" x mod 10 ="+x%10);

System.out.println(" y mod 10 ="+y%10);

}

}

OUTPUT:-

Q.16:-WAP IN JAVA TO DISPLAY SIMPLE STRING.

public class Name{

public static void main(String args[]){

System.out.print("MY COLLEGE NAME IS =MANUU POLY DBG");

System.out.print("         MY NAME IS = Shobi");

}

}

OUTPUT:-

Q.17:-WAP IN JAVA TO DISPLAY ASSIGNMENT OPERATOR.

public class Operator{

public static void main(String args[]){

int a=1;

int a=2;

int a=3;

a+=5;

b*=4;

c+=a*b;

c%=6;

System.out.println("a="+a);

System.out.println("b="+b);

System.out.println("c="+c);

}

}

OUTPUT:-

Q.18:-WAP IN JAVA TO FIND FORMULA OF VOLUME.

class Razii

{

double a;

double b;

double c;

}

class Raziii

{

public static void main(String args[])

{

Razii ob=new Razii();

double vol;

ob.a=10;

ob.b=15;

ob.c=20;

vol=ob.a*ob.b*ob.c;

System.out.println(+vol);

}

}

OUTPUT:-

Q.19:-

public class Rest{

                public static void main(String args[]){

int x;

for(x=1; x<=10; x++)

System.out.println("x is="+x);

}

}

OUTPUT:-

Q.20:-WAP IN JAVA TO FIND FORMULA OF VOLUME USING CONSTRUCTOR.

class Rox{

double width;

double height;

double depth;

Rox(double w,double h,double d)

{

                 width=w;

                 height=h;

                depth=d;

}

double volume()

{

                return(width*height*depth);

}

}

class Roxsample{

public static void main(String args[]){

Rox b1=new Rox(10,20,15);

double vol=b1.volume();

System.out.println("this is vol="+vol);

}

}

OUTPUT:-

Q.21:-WAP IN JAVA TO ADD SOME NUMBERS.

class Mal

{

int a=2;

int b=2;

int sum;

int add()

{

                return(a*a+b*b+2*a*b);

}

}

class Sall

{

public static void main(String args[])

{

Mal ob=new Mal();

System.out.println(+sum);

int sum=ob.add();

}

}

OUTPUT:-

Q.22:-WAP IN JAVA TO FIND FORMULA OF VOLUME USING THIS OPERATOR.

class Sox{

double width;

double height;

double depth;

Sox(double w,double h,double d)

{

                 this.width=w;

                 this.height=h;

                this.depth=d;

}

double volume()

{

                return(width*height*depth);

}

}

class Soxsample{

public static void main(String args[]){

Rox b1=new Rox(10,20,15);

double vol=b1.volume();

System.out.println("this is vol="+vol);

}

}

OUTPUT:-

Q.23:-WAP IN JAVA TO DISPLAY PASCAL TRIANGLE IN 01 TO 15.

public class Tarray{

                public static void main(String args[]){

                int twod[][]=new int [5][5];

                //int twod[0]=new int [1];

                //int twod[1]=new int [2];

                //int twod[2]=new int [3];

                //int twod[3]=new int [4];

                //int twod[4]=new int [5];

                int i,j,k=1;

                for(i=0;i<5;i++)

                {

                for(j=0;j<i+1;j++)

                {

                twod[i][j]=k;

                k++;

                }

                }

                for(i=0;i<5;i++)

                {

                for(j=0;j<i+1;j++)

                {

                System.out.print(twod[i][j] + " ");

                }

                System.out.println(" " );

                }

                }

                }

OUTPUT:-

Q.24:-WAP IN JAVA TO DISPLAY SIMPLE PROGRAM.

public class Test{

public static void main(String args[]){

System.out.println(" i am pass HAHAHAHA");

}

}

OUTPUT:-

 

Q.25:-WAP IN JAVA TO ADD TWO MATRIX USING ARRAY.

public class Toarray{

                public static void main(String args[]){

                int a[][]=new int [3][3];

                int b[][]=new int [3][3];

                int c[][]=new int [3][3];

                int i,j,k=0;

                for(i=0;i<3;i++)

                {

                for(j=0;j<3;j++)

                {

                                a[i][j]=k;

                                k++;

                }

                }

                System.out.println(" this is 1st matrix");

                for(i=0;i<3;i++)

                {

                for(j=0;j<3;j++)

                {

                System.out.print(a[i][j]+" ");

                }

                System.out.println( );

                }

                for(i=0;i<3;i++)

                {

                for(j=0;j<3;j++)

                {

                                b[i][j]=k;

                                k++;

                }

                }

                System.out.println(" this is 2nd matrix");

                for(i=0;i<3;i++)

                {

                for(j=0;j<3;j++)

                {

                System.out.print(b[i][j]+" ");

                }

                System.out.println( );

                }

                for(i=0;i<3;i++)

                {

                for(j=0;j<3;j++)

                {

                                c[i][j]=a[i][j]+b[i][j];

                }

                }

                System.out.println(" this is resultant  matrix");

                for(i=0;i<3;i++)

                {

                for(j=0;j<3;j++)

                {

                System.out.print(c[i][j]+" ");

                }

System.out.println( );

}

}

}

OUTPUT:-

Q26;-WAP IN JAVA TO FIND FORMULA OF VOLUME.

class tox{

double width;

double height;

double depth;

double volume()

{

                return(width*height*depth);

}

}

class Toxsample{

public static void main(String args[]){

tox b1=new tox();

b1.width=10;

b1.height=20;

b1.depth=15;

double vol=b1.volume();

System.out.println("this is vol="+vol);

}

}

OUTPUT:-

Q.27:-WAP IN JAVA TO FIND FORMULA OF VOLUME.

class toxx{

double width;

double height;

double depth;

void volume()

{

                System.out.println("this is volume=");

                System.out.println(width*height*depth);

}

}

class Toxxsample{

public static void main(String args[]){

toxx b1=new toxx();

toxx b2=new toxx();

b1.width=10;

b1.height=20;

b1.depth=15;

b2.width=10;

b2.height=20;

b2.depth=15;

b1.volume();

b2.volume();

}

}

OUTPUT:-

Q.28:-WAP IN JAVA TO DISPLAY 01 TO 19 USING ARRAY.

public class Twoarray{

                public static void main(String args[]){

                int twod[][]=new int [4][5];

                int i,j,k=0;

                for(i=0;i<4;i++)

                {

                for(j=0;j<5;j++)

                {

                twod[i][j]=k;

                k++;

                }

                }

                for(i=0;i<4;i++)

                {

                for(j=0;j<5;j++)

                {

                System.out.print(twod[i][j] + " ");

                }

                System.out.println(" " );

                }

                }

                }

OUTPUT:-

Q:-WAP IN JAVA TO ADD TWO NUMBER USING PACKAGE.

package manuu;

public class abc

{

                int a=10,b=10;

                public void add()

                {

                                int sum;

                                sum=a+b;

                                System.out.println(sum);

                }

}

import manuu.*;

public class main

{

public static void main(String args[])

{

                abc ob=new abc();

                ob.add();

}

}

OUTPUT:-

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Tausif

Hi! My name is TAUSIF AHMAD I have completed B.Tech in Computer Science from Maulana Azad National Urdu University Hyderabad. I am always ready to have new experiences meet new people and learn new things. 1. I am very interested in Frontend Development. 2. I love video editing and graphics designing. 3. I enjoy challenges that enables to grow. 4. I am part time Blogger.

Post a Comment (0)
Previous Post Next Post