1.write A Program To Print " Welcome To Java Programming" On The Screen
1.write A Program To Print " Welcome To Java Programming" On The Screen
class Qno1sol
import java.io.*;
class Qno2sol
try
int a=Integer.parseInt(ds.readLine());
int b=Integer.parseInt(ds.readLine());
int c=Integer.parseInt(ds.readLine());
if(a>b )
if(b>c )
if(c>a )
catch(IOException e)
System.out.println("There is problem"+e);
3.Using switch and case statements write a program to add, subtract , multiply and divide the
two numbers.
import java.io.*;
//int i=4;
int m,n;
m=10;
n=5;
switch(i)
case 1:
System.out.println("Addition"+" "+(m+n));
break;
case 2:
System.out.println("Substration"+" "+(m-n));
break;
case 3:
System.out.println("Multiplication"+" "+(m*n));
break;
case 4:
System.out.println("Division"+" "+(m/n));
break;
default:
break;
}
4.Using for loop write a program to add the integers up to 50 and print the result on the
screen.
class Qno4sol
for(int i=1;i<=50;i++)
System.out.println(i);
SUM=SUM+i;
class Qno5sol
Qno5sol()
int n[]={2,3,4,5,6,7,92,65,45,87};
int a,max,min,b;
max=n[0];
min=n[0];
for(int i=1;i<10;i++)
if(n[i]>max)
max=n[i];
if(n[i]<min)
min=n[i];
new Qno5sol();
6.Write a program to find the even sum and the odd sum in the given array.
class Qno6sol
for(int i=0;i<10;i++)
{
if(n[i]%2==0)
sum1=sum1+n[i];
else
sum2=sum2+n[i];
class Qno7sol
//int y[3][3]
int x[][]={{1,2,3},{4,5,6},{7,8,9}};
int y[][]={{11,12,13},{14,15,16},{17,18,19}};
int a[][];
int b[][];
static int c[][];
Qno7sol()
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
System.out.println();
System.out.println("*****First Matrix*****");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
System.out.print(y[i][j]+" ");
System.out.println();
System.out.println("*****Second Matrix*****");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
System.out.print(x[i][j]+y[i][j]+" ");
System.out.println();
System.out.println("*****Additional Matrix*****");
}
public static void main(String args[])
new Qno7sol();
8.Write a class rectangle which consists of functions getdata() and area(), and also write a
main program to create a rectangle object and to find the area by calling the function area ()
in rectangle class and display the result on the screen.
import java.io.*;
class Qno8sol
int height,width;
try
height=Integer.parseInt(ds.readLine());
width=Integer.parseInt(ds.readLine());
catch(IOException ex)
{
System.out.println("There is some error"+ex);
for(int i=0;i<height;i++)
System.out.println("|");
for(int i=0;i<width;i++)
System.out.print("-");
System.out.println("|");
System.out.print("-");
sol.getData();
sol.area();
9.Write a class Box with the variable width, depth and height and constructor to assigning the
values for these variables and a method to find the volume of the box and also write the
main program, which creates the box object, and find the volume of the box. Print the result
on the screen.
class Qno9sol
Qno9sol()
width=10;
depth=5;
height=20;
void volume()
int box=width*depth*height;
box.volume();
void add(int a)
System.out.println(a);
System.out.println(x+y);
q.add(10);
q.add(20,30);
class a
String s="Nitesh";
void display()
System.out.println(s);
}
void display()
System.out.println(s+" "+"Gaurav");
n.display();
class Qno12sol
String a1="Nitesh";
String a2="Gaurav";
System.out.println(a1.concat(" "+a2));
}
13.Write a program to find whether two given strings are equal or not and print the result on
the screen.
import java.io.*;
class Qno13sol
s1=br.readLine();
System.out.println(s1);
s2=br.readLine();
System.out.println(s2);
if(s1.equals(s2))
else
import java.io.*;
class Qno14sol
{
String str;
System.out.println("----------******----------");
System.out.println("----------******----------");
System.out.println("\n");
do
str=br.readLine();
int textLength=str.length();
for(int i=0;i<textLength;i++)
char ch=Character.toUpperCase(str.charAt(i));
System.out.print(ch);
}while(!str.equals("exit"));
}
15.Write a program to create a thread by extending the thread class.
static int i;
for(i=0;i<=5;i++)
new a().start();