1.(a) Write a java program to multiply two given matrices.
class Array58 { public static void main(String[] args) { int i,j,k; int [][] a={{1,2,3},{4,5,6},{7,8,9}}; int [][] b={{9,8,7},{6,5,4},{3,2,1}}; int [][]c=new int[3][3]; for (i=0;i<[Link];i++) { for (j=0;j<a[i].length;j++) { [Link](a[i][j]+" "); } [Link](" "); } [Link](" "); for (i=0;i<[Link];i++ ) { for (j=0;j<b[i].length;j++) { [Link](b[i][j]+" "); } [Link](" "); } [Link](" "); for(i=0;i<[Link];i++) { for(j=0;j<[Link];j++) { c[i][j]=0; for(k=0;k<[Link];k++) { c[i][j]+=a[i][k]*b[k][j]; } [Link](c[i][j]+" "); } [Link](" "); } } }
1.(b)Write a java program to handle mouse events and keyboard events import [Link].*; import [Link]; import [Link].*; import [Link].*; /* */ public class Mouse extends Applet implements MouseListener,MouseMotionListener { String txt=""; int x=10,y=30; public void init() { addMouseListener(this); addMouseMotionListener(this); } public void mouseClicked(MouseEvent me) { txt="Mouse Clicked"; setForeground([Link]); repaint(); } public void mouseEntered(MouseEvent me) { txt="Mouse Entered"; repaint(); } public void mouseExited(MouseEvent me) { txt="Mouse Exited"; setForeground([Link]); repaint(); } public void mousePressed(MouseEvent me) { txt="Mouse Pressed"; setForeground([Link]); repaint(); } public void mouseMoved(MouseEvent me) { txt="Mouse Moved"; setForeground([Link]); repaint(); } public void mouseDragged(MouseEvent me) { txt="Mouse Dragged"; setForeground([Link]);
repaint(); } public void mouseReleased(MouseEvent me) { txt="Mouse Released"; setForeground([Link]); repaint(); } public void paint(Graphics g) { [Link](txt,30,40); showStatus("Mouse events Handling"); } } 2.(a)Write a java program to write Applets to draw various polygons.
import [Link].*; import [Link].*; public class CircleLine extends Applet{ int x=300,y=100,r=50; public void paint(Graphics g){ [Link](3,300,200,10); [Link]("Line",100,100); [Link](x-r,y-r,100,100); [Link]("Circle",275,100); [Link](400,50,200,100); [Link]("Rectangel",450,100); } } Here is the HTML code of the program:
<HTML> <HEAD> </HEAD> <BODY>
<div align="center"> <APPLET CODE="[Link]" WIDTH="800" HEIGHT="500"></APPLET> </div>
</BODY> </HTML>
2. (b)Write a java program to count number of words and characters in a text.
import [Link]; import [Link]; public class FileWordVowelCounter { public static void main(String[] args) throws Exception { Scanner in = new Scanner(new File("[Link]")); int nbWords = 0; int nbVowels = 0; while([Link]("\\S+")) { String word = [Link]("\\S+"); nbVowels += getNbVowels(word); nbWords++; } [Link](nbWords); [Link](nbVowels); } public static int getNbVowels(String word) { int result = 0; char[] chars = [Link](); for(Character c : chars) { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { result++; }} return result; } }