Assignment On Java Programming Practical
Assignment On Java Programming Practical
MSc. IT.
SEMESTER- I
INSTRUCTIONS:
Signature:
ANSWER:
import java.util.Scanner;
if(m % n == 0){
return false;
return true;
int input;
input = in.nextInt();
if(fg.isPrimeNumber(input))
else
import java.util.Scanner;
int m, n, p, q, sum = 0, c, d, k;
m = in.nextInt();
n = in.nextInt();
first[c][d] = in.nextInt();
p = in.nextInt();
q = in.nextInt();
if ( n != p )
else
second[c][d] = in.nextInt();
multiply[c][d] = sum;
sum = 0;
}
}
System.out.print(multiply[c][d]+"\t");
System.out.print("\n");
}
3) Write a Java program to determine the order of numbers generated randomly using
Random class
ANSWER:
import java.util.Random;
import java.util.Arrays;
randomNumbers[i] = randomInteger;
int i, j, temp;
for ( j = i + 1; j <joseearray.length; j ++ )
temp = joseearray[ i ];
joseearray[ i ] = joseearray[ j ];
joseearray[ j ] = temp;
}
return joseearray;
int i, j, temp;
temp = joseearray[ i ];
joseearray[ i ] = joseearray[ j ];
joseearray[ j ] = temp;
return joseearray;
}
}
ANSWER:
return (j1+j2)/2;
return (j1+j2)/2;
return (j1+j2+j3)/3;
ANSWER:
import java.util.*;
int j, p, result;
Scanner input = new Scanner(System.in);
j = input.nextInt();
p = input.nextInt();
// try block
try {
result = j/ p;
// catch block
catch (ArithmeticException e) {
}
Assignment-B
ANSWER:
try
Thread.sleep (1000);
*thread is interrupted.
*/
}
}
try
{
Thread.sleep(1000);
}
catch (InterruptedException interruptedException)
{
/*Interrupted exception will be thrown when a sleeping or waiting
* thread is interrupted.
*/
}
}
}
}
public class ThreadDemo
thread1.start();
thread2.start();
}
Flowchart
Output
ANSWER:
T1.start();
T2.start();
try
T1.join();
T2.join();
catch( Exception e)
System.out.println("Interrupted");
private Thread t;
private String threadName;
PrintDemo PD;
threadName = name;
PD = pd;
synchronized(PD) {
PD.printCount();
if (t == null)
t.start ();
}
Print Demo program
class PrintDemo {
try {
} catch (Exception e) {
System.out.println("Thread interrupted.");
Flowchart
Output
ANSWER:
import java.awt.*;
import java.awt.event.*;
class JoseeFrame
screen.setSize(300,300);
screen.setVisible(true);
// constructor
public GuiFrame(String s)
setBackground(Color.cyan);
setLayout(new FlowLayout());
add(pushButton);
pushButton.addActionListener(this);
if (event.getActionCommand().equals("click to close"))
System.exit(0);
}
}
Flowchart
4) Write an applet program to illustrate the Menu and Submenu controls
ANSWER:
import java.awt.*;
class AWTMenu extends Frame
{
MenuBar mbar;
Menu menu,submenu, chips;
MenuItem m1,m2,m3,m4,m5,m9,m10;
public AWTMenu()
{
// Create MenuItems
m1=new MenuItem("math physics");
m2=new MenuItem("computer science");
m3=new MenuItem("network plus");
ANSWER:
import java.awt.*;
import java.applet.*;
{
//this is 4 drawpolygon
int xs[]={40,49,60,70,57,40,35};
int ys[]={260,310,315,280,260,270,265};
//this is 4 fillpolygon
int xss[]={140,150,180,200,170,150,140};
int yss[]={260,310,315,280,260,270,265};
g.fillRect(140,70,70,40);//same as above
g.setColor(Color.green);
g.drawString("2.Squares ",40,130);
g.drawLine(40,140,200,140);//x1,y1-starting point,x2,y2-ending point coordinates
g.drawString("3.Ovals ",40,210);
g.drawLine(40,220,200,220);
g.drawOval(40,230,70,40);
g.fillOval(140,230,70,40);
g.setColor(Color.blue);
g.drawString("4.Circles ",40,290);
g.drawLine(40,300,200,300);
g.drawOval(40,310,40,40);
g.fillOval(140,310,40,40);
g.setColor(Color.black);
g.drawString("5.Triangle ",40,370);
g.drawLine(40,380,200,380);
g.drawLine(40,390,40,430);
g.drawLine(40,390,200,390);
g.drawLine(40,430,200,390);
g.setColor(Color.cyan);
g.drawLine(40,480,200,470);
g.drawString("6.ARC",40,470);
g.drawArc(40, 490, 75, 95, 0, 90);
g.fillArc(140, 490, 75, 95, 0, 90);
}
}
<HTML>
<HEAD>
<title>Hello World Applet</title>
</HEAD>
<BODY><b>
<applet codebase="c:\Users\HP\Desktop\javafile" code="SomeShapes.class" width=300
height=600>
</applet><b>
</BODY>
</HTML>
flowchart