PART A. input as command line argument. 1. Write a program to find factorial of list of number reading
|
|
- Egbert McGee
- 6 years ago
- Views:
Transcription
1 PART A 1. Write a program to find factorial of list of number reading input as command line argument class factorial public static void main(string args[]) int[]arr=new int[10]; int fact; if(args.length==0) System.out.println("No command line argument"); return; for(int i=0;i<args.length;i++) arr[i]=integer.parseint(args[i]); for(int i=0;i<args.length;i++) fact=1; while(arr[i]>0) fact=fact*arr[i]; arr[i]--; System.out.println("The factorial of"+args[i]+"is:"+fact);
2 2. Write a program to display all prime numbers between two limits class Prime public static void main(string args[]) if(args.length==0) System.out.println("No command line arguments"); return; int num1, num2, i, j, n; num1 = Integer.parseInt(args[0]); num2 = Integer.parseInt(args[1]); System.out.println("Prime numbers between "+num1+" and "+num2+" are"); for(i=num1; i<num2; i++) for(j=2; j<i; j++) n=i%j; if(n==0) break; if(i==j) System.out.println(i);
3 3. Write a program to sort list of elements in ascending and descending order and show the exception handling class Sorting public static void main(string args[]) int a[]=new int[5]; try for(int i=0;i<5;i++) a[i]=integer.parseint(args[i]); System.out.println("\nBefore Sorting\n"); for(int i=0;i<5;i++) System.out.print(" "+a[i]); bubblesort(a,5); System.out.println("\n\nAfter Sorting\n"); System.out.println("Ascending order\n"); for(int i=0;i<5;i++) System.out.print(" "+a[i]); System.out.println("\n\nDescending order\n"); for(int i=4;i>=0;i--) System.out.print(" "+a[i]); catch(numberformatexception e) System.out.println("Enter only Integer"); catch(arrayindexoutofboundsexception e) System.out.println("Enter only 5 integer"); public static void bubblesort(int[] arr,int length)
4 int temp,i,j; for(i=0;i<length-1;i++) for(j=0;j<length-1-i;j++) if(arr[j]>arr[j+1]) temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp;
5 4. Write a program to implement all string operations import java.lang.*; class StringOperation public static void main(string[] args) String str1 = "Sudeep"; String str2 = "Naresh"; System.out.println("The String are " +str1 + " and " + str2); int len1 = str1.length(); int len2 = str2.length(); System.out.println("The length of " +str1 + " and " + str2 + " is" +len1 + " and " +len2);system.out.println("concartination of " +str1 + "and" + str2 +" is " + str1.concat(str2)); System.out.println("First Character of" +str1 + " is " + str1.charat(0));system.out.println("the Upper Case of" + str1 +" is " + str1.touppercase()); System.out.println("The Lower Case of" + str2 +" is " + str1.tolowercase()); System.out.println("d occurs at position" + str1.indexof('d') + " in " + str1); System.out.println("The substring of " + str1 +" which starts from index 2 and ends at index 5 is " + str1.substring(2,5)); System.out.println("Repalacing d with D in " + str1 + " is " + str1.repalce('d','d')); boolean check = str1.equals(str2); if (check == false) System.out.println("Both String are different"); else System.out.println("Both String are Same");
6
7 5. Write a program to find area of geometrical figures using method import java.lang.math.*; import java.io.*; class GeometricalArea public static double circlearea(double r) return Math.PI*r*r; public static double squarearea(double side) return side*side; public static double rectanglearea(double length, double breadth) return length * breadth; public static double trianglearea(double base, double height) return 0.5*base*height; public static String readline() throws IOException String input=""; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); input = br.readline(); return input; public static void main(string[] args) throws IOException System.out.println("Enter the Radius:"); double radius = Double.parseDouble(readline());
8 System.out.println("Area of Circle:"+circleArea(radius)); System.out.println("Enter the Side:"); double side = Double.parseDouble(readline()); System.out.println("Area of Square:"+squareArea(side)); System.out.println("Enter the Length:"); double length = Double.parseDouble(readline()); System.out.println("Enter the Breadth:"); double breadth = Double.parseDouble(readline()); System.out.println("Area of Rectangle:"+rectangleArea(length, breadth)); System.out.println("Enter the Base:"); double base = Double.parseDouble(readline()); System.out.println("Enter the Height:"); double height = Double.parseDouble(readline()); System.out.println("Area of Triangle:"+triangleArea(base, height));
9 6. Write a program to implement constructor overloading by passing different number of parameter of different types class Cube int length, breadth, height; Cube() length = breadth = height = 2; System.out.println("This is the default Constructor"); Cube(int l, int b) length = l; breadth = b; height = 2; System.out.println("This is the paratemerized constructor with two arguments"); Cube(int l, int b, int h) length = l; breadth = b; height = h; System.out.println("This is the paratemerized constructor with three arguments"); int getvolume() return length*breadth*height; public static void main(string args[]) Cube obj1 = new Cube(); System.out.println("The volume of the cube is"+obj1.getvolume());
10 Cube obj2 = new Cube(10,20); System.out.println("The volume of the cube is"+obj2.getvolume()); Cube obj3 = new Cube(10,20,30); System.out.println("The volume of the cube is"+obj3.getvolume());
11 7. Write a program to create student report using applet, read the input using text boxes and display the o/p using buttons import java.applet.*; import java.awt.*; import java.awt.event.*; /*<applet code="studentreport.class",width=500 height=500> </applet>*/ public class StudentReport extends Applet implements ActionListener Label lbltitle,lblregno,lblcourse,lblsemester,lblsubject1,lblsubject2; TextField txtregno,txtcourse,txtsemester,txtsubject1,txtsubject2; Button cmdreport; String rno="",course="",sem="",sub1="",sub2="",avg="",heading=""; public void init() GridBagLayout gbag=new GridBagLayout(); GridBagConstraints gbc=new GridBagConstraints(); setlayout(gbag); lbltitle=new Label("Enter Student Details"); lblregno=new Label("Register Number"); txtregno=new TextField(25); lblcourse=new Label("Course Name"); txtcourse=new TextField(25); lblsemester=new Label("Semester"); txtsemester=new TextField(25); lblsubject1=new Label("Mark of Subject 1:"); txtsubject1=new TextField(25); lblsubject2=new Label("Mark of Subject 2:"); txtsubject2=new TextField(25); cmdreport=new Button("View Report"); gbc.weighty=1.0; gbc.gridwidth=gridbagconstraints.remainder;
12 gbc.anchor=gridbagconstraints.north; gbag.setconstraints(lbltitle,gbc); gbc.anchor=gridbagconstraints.east; gbc.gridwidth=gridbagconstraints.relative; gbag.setconstraints(lblregno,gbc); gbc.gridwidth=gridbagconstraints.remainder; gbag.setconstraints(txtregno,gbc); gbc.gridwidth=gridbagconstraints.relative; gbag.setconstraints(lblcourse,gbc); gbc.gridwidth=gridbagconstraints.remainder; gbag.setconstraints(txtcourse,gbc); gbc.gridwidth=gridbagconstraints.relative; gbag.setconstraints(lblsemester,gbc); gbc.gridwidth=gridbagconstraints.remainder; gbag.setconstraints(txtsemester,gbc); gbc.gridwidth=gridbagconstraints.relative; gbag.setconstraints(lblsubject1,gbc); gbc.gridwidth=gridbagconstraints.remainder; gbag.setconstraints(txtsubject1,gbc); gbc.gridwidth=gridbagconstraints.relative; gbag.setconstraints(lblsubject2,gbc); gbc.gridwidth=gridbagconstraints.remainder; gbag.setconstraints(txtsubject2,gbc); gbc.anchor=gridbagconstraints.center; gbag.setconstraints(cmdreport,gbc); add(lbltitle); add(lblregno); add(txtregno); add(lblcourse); add(txtcourse); add(lblsemester); add(txtsemester); add(lblsubject1); add(txtsubject1); add(lblsubject2);
13 add(txtsubject2); add(cmdreport); cmdreport.addactionlistener(this); public void actionperformed(actionevent ae) try if(ae.getsource()==cmdreport) rno=txtregno.gettext().trim(); course=txtcourse.gettext().trim(); sem=txtsemester.gettext().trim(); sub1=txtsubject1.gettext().trim(); sub2=txtsubject2.gettext().trim(); avg="avg Marks" +((Integer.parseInt(sub1)+Integer.parseInt(sub2))/2); rno="register Number:"+rno; course="course:"+course; sem="semester:"+sem; sub1="subject1:"+sub1; sub2="subject2:"+sub2; heading="student Report"; removeall(); showstatus(""); repaint(); catch(numberformatexception exc) showstatus("invalid Data"); public void paint(graphics g) g.drawstring(heading,30,30);
14 g.drawstring(rno,30,80); g.drawstring(course,30,100); g.drawstring(sem,30,120); g.drawstring(sub1,30,140); g.drawstring(sub2,30,160); g.drawstring(avg,30,180);
15 8. Write a program to calculate bonus for different departments using method overriding abstract class Departement double salary, bonus, totalsalary; public abstract void calbonus(double salary); public void displaytotalsalary(string dept) System.out.println(dept + "\t" + bonus + "\t" + totalsalary); class Accoutnts extends Departement public void calbonus(double sal) salary = sal; bonus = sal * 0.2; totalsalary = salary + bonus; class Sales extends Departement public void calbonus(double sal) salary = sal; bonus = sal * 0.3; totalsalary = salary + bonus; public class BonusCalculate public static void main(string[] args) Departement acc = new Accoutnts();
16 Departement sales = new Sales(); acc.calbonus(10000); sales.calbonus(20000); System.out.println("Departement \t Basic Salary \t Bonus \t Total Salary"); System.out.println(" "); acc.displaytotalsalary("accoutnts"); sales.displaytotalsalary("sales");
17 9. Write a program to implement thread,applets and graphics by implementing animation of ball moving import java.applet.*; import java.awt.*; /*<applet code="movingball" width=200 height=200> </applet>*/ public class MovingBall extends Applet implements Runnable int x=150,y=50,r=50; int dx=11,dy=7; Thread animator; volatile boolean pleasestop; public void paint(graphics g) g.setcolor(color.red); g.filloval(x-r,y-r,r*2,r*2); public void animate() Rectangle bounds=getbounds(); if((x-r+dx<0) (x+r+dx>bounds.width)) dx=-dx; if((y-r+dy<0) (y+r+dy>bounds.height)) dy=-dy; x+=dx; y+=dy; repaint(); public void run() while(!pleasestop) animate(); try
18 Thread.sleep(100); catch(interruptedexception e) public void start() animator=new Thread(this); pleasestop=false; animator.start(); public void stop() pleasestop=true;
19 10. (a) Write a program to implement mouse events. import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet code="mouseevents" width=300 height=300> </applet>*/ public class MouseEvents extends Applet implements MouseListener,MouseMotionListener String str=""; public void init() addmouselistener(this); addmousemotionlistener(this); public void paint(graphics g) g.drawstring(str,20,20); public void mousepressed(mouseevent me) str="mouse Button Pressed"; repaint(); public void mouseclicked(mouseevent me) str="mouse Button Clicked"; repaint(); public void mousereleased(mouseevent me) str="mouse Button Released"; repaint();
20 public void mouseentered(mouseevent me) str="mouse Entered"; repaint(); public void mouseexited(mouseevent me) str="mouse Exited"; repaint(); public void mousemoved(mouseevent me) str="mouse Moved"; repaint(); public void mousedropped(mouseevent me) str="mouse Dropped"; repaint(); public void mousedragged(mouseevent me) str="mouse Dragged"; repaint();
21 10. (b)write a program to implement keyboard events import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet code="keyboardevents"width=400 height=400> </applet> */ public class KeyBoardEvents extends Applet implements KeyListener String str=""; public void init() addkeylistener(this); requestfocus(); public void keytyped(keyevent e) str +=e.getkeychar(); repaint(0); public void keypressed(keyevent e) showstatus("key PRESSED"); public void keyreleased(keyevent e) showstatus("key RELEASED"); public void paint(graphics g) g.drawstring(str,15,15);
22 PART B 1. Write a program to demonstrate inheritance import java.io.*; import java.util.*; class TwoDshape double width, height; void showdim() System.out.println("Width and Height are:" + width + " and "+ height); class Triangle extends TwoDshape String style; double area() return (width * height) / 2; void showstyle() System.out.println("Triangle is" +style); class Shape public static void main(string[] args) throws IOException Triangle t1 = new Triangle(); Triangle t2 = new Triangle(); t1.width = 4.0; t1.height = 4.0; t1.style = "Filled";
23 t2.width = 4.0; t2.height = 4.0; t2.style = "Outlined"; System.out.println("Information about Triangle 1"); t1.showstyle(); t1.showdim(); System.out.println("Area is" +t1.area()); System.out.println("Information about Triangle 2"); t2.showstyle(); t2.showdim(); System.out.println("Area is" +t2.area());
24 2. Write a program to demonstrate this keyword class ThisDemo int i,j; ThisDemo() this(100, 200); System.out.println("No Argument Passed"); ThisDemo(int i, int j) this.i = i; this.j = j; void display() System.out.println("The value of i is: "+i); System.out.println("The value of j is: "+j); public static void main(string args[]) ThisDemo d1 = new ThisDemo(); d1.display();
25 3. Write a program to demonstrate wrapper class and its method import java.*; public class WrapperObject public static void main(string args[]) int i=100; Integer i1 = new Integer(i); Integer i2 = Integer.valueOf("123"); System.out.println("The premetive value of I! is:"+i1.intvalue()); System.out.println("The premetive value of I2 is:"+i2.intvalue()); String str1 = "1234"; int num2 = Integer.parseInt(str1); System.out.println("Value of num2: "+num2); System.out.println("The string value of I1 is:"+i1.tostring()); System.out.println("The string value of I2 is:"+i2.tostring());
26 4. Write a program to create an array of 5 elements find min and max elements import java.io.*; import java.util.*; class ArrayDemo public static void main(string args[]) throws IOException int[] x = new int[5]; int[] y = new int[x.length]; Scanner s = new Scanner(System.in); System.out.println("Enter array elements:"); for(int i=0; i<x.length; i++) x[i] = s.nextint(); System.out.println("Array Elements are:"); for(int i=0; i<x.length; i++) System.out.println(x[i]); y[i] = x[i]; System.out.println("After Copying Array Element are:"); for(int i=0; i<x.length; i++) System.out.println(y[i]); int min, max; min = max = x[0]; for(int i=0; i<x.length; i++) if(x[i] > max) max = x[i]; if(x[i] < min) min = x[i];
27 System.out.println("Maximum Value"+max); System.out.println("Minimum Value:"+min);
28 5. Write a program to demonstrate vectors import java.util.*; class VectorDemo public static void main(string args[]) Vector<String> v = new Vector<String>(); v.add("c"); v.add("java"); v.add("c++"); v.add("vb"); System.out.println("Initial Vector Content :" +v.tostring()); System.out.println("Last Element :" +v.lastelement()); System.out.println("Element at 2nd position :" +v.elementat(2)); v.insertelementat("fam", 2); v.insertelementat("c#", 0); System.out.println("After Inserting Vector Content :" +v.tostring()); v.removeelement(3); System.out.println("After Removing Vector Content :" +v.tostring()); v.setelementat("ds", 3); v.remove("vb"); System.out.println("After Removing 'VB' Vector Content :" +v.tostring());
29 6. Write a program to implement multiple inheritance with interface import java.io.*; class Student int rollnumber; void getnumber(int n) rollnumber = n; void putnumber() System.out.println("Roll Number:" +rollnumber); class Test extends Student float part1, part2; void getmarks(float m1, float m2) part1 = m1; part2 = m2; void putmarks() System.out.println("Marks Obtained:"); System.out.println("Part 1:"+part1); System.out.println("Part 2:"+part2); interface sports float sortwt = 6.0f; void putwt();
30 class Result extends Test implements sports float total; public void putwt() System.out.println("Sportwt:"+sortwt); void display() total = part1 + part2 + sortwt; putnumber(); putmarks(); putwt(); System.out.println("Total Score:"+total); class Hybrid public static void main(string[] args) Result student1 = new Result(); student1.getnumber(1234); student1.getmarks(27.5f, 43.5f); student1.display();
31 7. Write a program to demonstrate static variable and static method import java.io.*; class staticmethod static int val = 1024; static int valdiv2() return val/2; class Demo public static void main(string[] args) System.out.println("Value is:" +staticmethod.val); System.out.println("staticMethod.valDiv2():" +staticmethod.valdiv2()); staticmethod.val = 4; System.out.println("Value is:"+staticmethod.val); System.out.println("staticMethod.valDiv2():" +staticmethod.valdiv2());
32 8. Write a program to demonstrate multithreading class ThreadOne extends Thread public void run() for(int i=0;i<=10;i++) System.out.println(Thread.currentThread().getName()+i); class ThreadTwo extends Thread public void run() for(int i=11;i<=20;i++) System.out.println(Thread.currentThread().getName()+i); class ThreadThree extends Thread public void run() for(int i=21;i<=25;i++) System.out.println(Thread.currentThread().getName()+i); class ThreadSample public static void main(string args[]) ThreadOne t1=new ThreadOne(); ThreadTwo t2=new ThreadTwo(); ThreadThree t3=new ThreadThree(); Thread tr1=new Thread(t1,"Thread One"); Thread tr2=new Thread(t2,"Thread Two");
33 Thread tr3=new Thread(t3,"Thread Three"); tr1.start(); tr2.start(); tr3.start(); for(int i=26;i<=30;i++) System.out.println(Thread.currentThread().getName()+i);
34 9. Write a program to demonstrate Synchronization class Parenthesis void display(string s) System.out.println(""+s); try Thread.sleep(1000); catch (InterruptedException e) System.out.println("Interrupted"); System.out.println(""); class MyThread extends Thread String s1; Parenthesis p1; Thread t; public MyThread(Parenthesis p2, String s2) p1=p2; s1=s2; public void run() p1.display(s1); class NonSynchronized
35 public static void main(string[] args) Parenthesis p3 = new Parenthesis(); MyThread ta1 = new MyThread(p3, "Acharya"); Thread t1 = new Thread(ta1); MyThread ta2 = new MyThread(p3, "College"); Thread t2 = new Thread(ta2); t1.start(); t2.start();
36 10. Write a program to demonstrate user defined exception class negetive extends Exception private int mynumber; public negetive(int mynumber) this.mynumber=mynumber; public String tostring() return "Number cannot be negetive"+""+mynumber; public class User public static void main(string args[]) throws Exception int mynumber=getnumber(); if(mynumber<0) throw new negetive(mynumber); else System.out.println("Number is"+mynumber); public static int getnumber() return -6;
Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*;
Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*; /* */ public
More informationObject-Oriented Programming
Object-Oriented Programming - Encapsulation Data & code bound together - > objects - Polymorphism Overloading of constructors & methods - Inheritance A class incorporates another class into its declaration
More informationINDEX SL.NO NAME OF PROGRAMS PAGE NO REMARKS PROGRAM TO FIND FACTORIAL OF THREE
INDEX SL.NO NAME OF PROGRAMS PAGE NO REMARKS PROGRAM TO FIND FACTORIAL OF THREE 1 NUMBERS PROGRAM FOR SUM OF SERIES USING 2 MATHPOWER METHOD 3 PROGRAM ON COMMAND LINE ARGUMENT 4 PROGRAM TO PRINT FIBONACI
More information/* Program that accepts a shopping list of five items from the command line and stores them in a vector */
/* Program that accepts a shopping list of five items from the command line and stores them in a vector */ import java.util.*; // load Vector class class ShoppingList public static void main(string args[
More informationCS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each
CS 120 Fall 2008 Practice Final Exam v1.0m Name: Model Solution True/False Section, 20 points: 10 true/false, 2 points each Multiple Choice Section, 32 points: 8 multiple choice, 4 points each Code Tracing
More informationPESIT Bangalore South Campus
INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)
More informationUNIT - V. Inheritance Interfaces and inner classes Exception handling Threads Streams and I/O
UNIT - V Inheritance Interfaces and inner classes Exception handling Threads Streams and I/O 1 INHERITANCE 2 INHERITANCE What is Inheritance? Inheritance is the mechanism which allows a class B to inherit
More informationExp 6: Develop Java programs to implement Interfaces and Packages. Apply Exception handling and implement multithreaded programs.
CO504.3 CO504.4 Develop Java programs to implement Interfaces and Packages. Apply Exception handling and implement multithreaded programs. CO504.5 CO504.6 Implement Graphics programs using Applet. Develop
More informationAssignment2013 Please use this document only for verifying if your programs are right. Do not blindly copy paste and waste your time.
Please use this document only for verifying if your programs are right. Do not blindly copy paste and waste your time. 11/3/2013 TechSparx Computer Training Center Saravanan.G Please use this document
More informationUNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.
UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING 1. What are Threads? A thread is a single path of execution of code in a program. A Multithreaded program contains two or more parts that can run concurrently.
More informationF I N A L E X A M I N A T I O N
Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student
More informationTHE UNIVERSITY OF AUCKLAND
CompSci 101 with answers THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2012 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this test.
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering
INTERNAL ASSESSMENT TEST 2 Date : 28-09-15 Max Marks :50 Subject & Code : JAVA&J2EE(10IS753) Section: VII A&B Name of faculty : Mr.Sreenath M V Time : 11.30-1.00 PM Note: Answer any five questions 1) a)
More informationPractical 1 Date : Statement: Write a program to find a factorial of given number by user. Program:
Practical 1 Date : Statement: Write a program to find a factorial of given number by user. Program: class Pract1 public static void main(string s[]) int n,a1; n=integer.parseint(s[0]); A a = new A(); a1
More informationMethod Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is
INDEX Event Handling. Key Event. Methods Of Key Event. Example Of Key Event. Mouse Event. Method Of Mouse Event. Mouse Motion Listener. Example of Mouse Event. Event Handling One of the key concept in
More informationB.Sc (Computer Science) Programming in Java Lab Programs
B.Sc (Computer Science) Programming in Java Lab Programs 1 1. Write java programs to find the following. a) Largest of given Three Numbers b) Reverses the digits of a number c) Given number is prime or
More informationGUI in Java TalentHome Solutions
GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator
More informationpackage p1; public class Derivation extends Protection { public Derivation() { System.out.println("Derived class constructor");
PROGRAM:1 WAP to implement the packages //package 1: package p1; public class Protection int n=1; public int n_pub=2; private int n_pri=3; protected int n_pro=4; public Protection () System.out.println("Base
More informationCHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA
1. JIT meaning a. java in time b. just in time c. join in time d. none of above CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA 2. After the compilation of the java source code, which file is created
More informationMYcsvtu Notes. Java Programming Lab Manual
Java Programming Lab Manual LIST OF EXPERIMENTS 1. Write a Program to add two numbers using Command Line Arguments. 2. Write a Program to find the factorial of a given number using while statement. 3.
More informationNITI NITI I PRIORITET
NITI public class ThreadsTest { public static void main(string args[]) { BytePrinter bp1 = new BytePrinter(); BytePrinter bp2 = new BytePrinter(); BytePrinter bp3 = new BytePrinter(); bp1.start(); bp2.start();
More informationpackage import public class public static void int out new for break else out else out
//1) WAP in JAVA to check whether no is prime or not. package finalpracs; import java.util.scanner; public class Prime public static void main(string args[]) int a, i, flag=0; System.out.println("Enter
More informationCSIS 10A Practice Final Exam Solutions
CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!=
More informationOBJECT ORIENTED PROGRAMMING TYm. Allotted : 3 Hours Full Marks: 70
I,.. CI/. T.cH/C8E/ODD SEM/SEM-5/CS-504D/2016-17... AiIIIII "-AmI u...iir e~ IlAULAKA ABUL KALAM AZAD UNIVERSITY TECHNOLOGY,~TBENGAL Paper Code: CS-504D OF OBJECT ORIENTED PROGRAMMING TYm. Allotted : 3
More informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview
More informationQuestion 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.
Name: 1.124 Quiz 2 Thursday November 9, 2000 Time: 1 hour 20 minutes Answer all questions. All questions carry equal marks. Question 1. Show the steps that are involved in sorting the string SORTME using
More informationJava Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,
Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also
More informatione) Implicit and Explicit Type Conversion Pg 328 j) Types of errors Pg 371
Class IX HY 2013 Revision Guidelines Page 1 Section A (Power Point) Q1.What is PowerPoint? How are PowerPoint files named? Q2. Describe the 4 different ways of creating a presentation? (2 lines each) Q3.
More informationPractical No: 1 Aim: Demonstrate round - robin scheduling using threads.
Practical No: 1 Aim: Demonstrate round - robin scheduling using threads. Source Code: RR.java import java.io.*; class job implements Runnable int process_id, no_of_instr,time_quantum; Thread t; job(int
More information7. MULTITHREDED PROGRAMMING
7. MULTITHREDED PROGRAMMING What is thread? A thread is a single sequential flow of control within a program. Thread is a path of the execution in a program. Muti-Threading: Executing more than one thread
More informationG51PRG: Introduction to Programming Second semester Applets and graphics
G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting
More informationB.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Lab Programs
B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Lab Programs 1 1. Write a java program to determine the sum of the following harmonic series for a given value of n. 1+1/2+1/3+...
More informationPrasanth Kumar K(Head-Dept of Computers)
B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Unit-II 1 1. Define operator. Explain the various operators in Java. (Mar 2010) (Oct 2011) Java supports a rich set of
More informationJava Intro 3. Java Intro 3. Class Libraries and the Java API. Outline
Java Intro 3 9/7/2007 1 Java Intro 3 Outline Java API Packages Access Rules, Class Visibility Strings as Objects Wrapper classes Static Attributes & Methods Hello World details 9/7/2007 2 Class Libraries
More information(2½ hours) Total Marks: 75
(2½ hours) Total Marks: 75 N. B.: (1) All questions are compulsory. (2) Makesuitable assumptions wherever necessary and state the assumptions mad (3) Answers to the same question must be written together.
More informationCSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015
CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet
More informationJava - Dates and Threads
Java - Dates and Threads Thread example Java uses threads to allow 1 event to break into another. If an action is to occur a number of times with a loop or to occur until some condition is satisfied then
More informationWrite a program which converts all lowercase letter in a sentence to uppercase.
Write a program which converts all lowercase letter in a sentence to uppercase. For Example: 1) Consider a sentence "welcome to Java Programming!" its uppercase conversion is " WELCOME TO JAVA PROGRAMMING!"
More information1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B
1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these 2. How many primitive data types are there in Java? A. 5 B. 6 C. 7 D. 8 3. In Java byte, short, int and long
More information2007/10/17 ソフトウェア基礎課題布広. /** * SOFT * AppletTest01.java * 文字表示 */
演習コメントを参考にして を埋めてアプレットプログラムを実行させてみよ * SOFT 120 01 * AppletTest01.java * 文字表示 //java の applet 定義 // 文字 絵を描くのに必要な Graphics を定義 public
More informationMULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
CSIS 10A PRACTICE FINAL EXAM SOLUTIONS Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What
More informationWeek 9. Abstract Classes
Week 9 Abstract Classes Interfaces Arrays (Assigning, Passing, Returning) Multi-dimensional Arrays Abstract Classes Suppose we have derived Square and Circle subclasses from the superclass Shape. We may
More informationJava for Interfaces and Networks (DT3010, HT10)
Java for Interfaces and Networks (DT3010, HT10) Mouse Events, Timers, Serialization Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces
More informationMultiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)
M257 MTA Spring2010 Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) 1. If we need various objects that are similar in structure, but
More informationBirkbeck (University of London) Software and Programming 1 In-class Test Mar 2018
Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment
More informationH212 Introduction to Software Systems Honors
Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,
More informationProgrammierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications
More informationComputer Science 210: Data Structures. Intro to Java Graphics
Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes
More informationThe AWT Event Model 9
The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow
More informationJohn Cowell. Essential Java Fast. How to write object oriented software for the Internet. with 64 figures. Jp Springer
John Cowell Essential Java Fast How to write object oriented software for the Internet with 64 figures Jp Springer Contents 1 WHY USE JAVA? 1 Introduction 1 What is Java? 2 Is this book for you? 2 What
More information/*** Title :- Program to print the following sequence of stars. * * * * * * * * *
/*** Title :- Program to print the following sequence of stars. * * * * * * * * * **************************************************************************************************/ class star public static
More informationJAVA. Lab 12 & 13: Multithreading
JAVA Prof. Navrati Saxena TA: Rochak Sachan Lab 12 & 13: Multithreading Outline: 2 What is multithreaded programming? Thread model Synchronization Thread Class and Runnable Interface The Main Thread Creating
More informationAN IMPROTANT COLLECTION OF JAVA IO RELATED PROGRAMS
JAVALEARNINGS.COM AN IMPROTANT COLLECTION OF JAVA IO RELATED PROGRAMS Visit for more pdf downloads and interview related questions JAVALEARNINGS.COM /* Write a program to write n number of student records
More informationChapter 5 Some useful classes
Chapter 5 Some useful classes Lesson page 5-1. Numerical wrapper classes Activity 5-1-1 Wrapper-class Integer Question 1. False. A new Integer can be created, but its contents cannot be changed. Question
More informationApplet which displays a simulated trackball in the upper half of its window.
Example: Applet which displays a simulated trackball in the upper half of its window. By dragging the trackball using the mouse, you change its state, given by its x-y position relative to the window boundaries,
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationRecursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples
Recursion General Algorithm for Recursion When to use and not use Recursion Recursion Removal Examples Comparison of the Iterative and Recursive Solutions Exercises Unit 19 1 General Algorithm for Recursion
More informationExample: Monte Carlo Simulation 1
Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149
More informationMultithreaded Programming
Multithreaded Programming Multithreaded programming basics Concurrency is the ability to run multiple parts of the program in parallel. In Concurrent programming, there are two units of execution: Processes
More informationGlobalLogic Technical Question Paper
GlobalLogic Technical Question Paper What is the output of the following code when compiled and run? Select two correct answers. public class Question01 { public static void main(string[] args){ int y=0;
More informationChapter 10. Further Abstraction Techniques
Chapter 10 Further Abstraction Techniques In the previous chapter, we saw how Java checks the usage of methods. We also saw that if the method is not defined in the superclass, the compiler will not work.
More informationComputer Applications Answer Key Class IX December 2017
Computer Applications Answer Key Class IX December 2017 Question 1. a) What are the default values of the primitive data type int and float? Ans : int = 0 and float 0.0f; b) Name any two OOP s principle.
More informationB2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA
B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE
More informationAnimation Part 2: MoveableShape interface & Multithreading
Animation Part 2: MoveableShape interface & Multithreading MoveableShape Interface In the previous example, an image was drawn, then redrawn in another location Since the actions described above can apply
More informationJ.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination.
THE I/O PACKAGE Java I/O is defined in terms of streams. J.73 import java.io.*; class Translate { public static void main(string[] args) { InputStream in = System.in; OutputStream out = System.out; J.74
More information1 Short Answer (10 Points Each)
1 Short Answer (10 Points Each) 1. Write a for loop that will calculate a factorial. Assume that the value n has been input by the user and have the loop create n! and store it in the variable fact. Recall
More informationIn this chapter, you will:
Java Programming: Guided Learning with Early Objects Chapter 4 Control Structures I: Selection In this chapter, you will: Make decisions with the if and if else structures Use compound statements in an
More informationCS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)
CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers
More informationPrashanth Kumar K(Head-Dept of Computers)
B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Unit-III 1 1. Define Array. (Mar 2010) Write short notes on Arrays with an example program in Java. (Oct 2011) An array
More informationChapter 1 GUI Applications
Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations
More informationAn applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a
CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled
More informationInterfaces. Interfaces. Implementing Interfaces. Interfaces : : : :
Interfaces Interfaces The implementation of a module should be separated from its contractual interface and hidden from the clients of the module Contractual Interface Implementation is hidden from the
More informationXII Informatics Practices 2013 important questions with solution
XII Informatics Practices 2013 important questions with solution 1. Why do you use import statement in java programming? Explain with example. Ans. The import statement in Java allows programmers to refer
More informationConcurrent Computing CSCI 201 Principles of Software Development
Concurrent Computing CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu Outline Threads Multi-Threaded Code CPU Scheduling Program USC CSCI 201L Thread Overview Looking
More information830512@itri.org.tw import java.net.socket; import java.net.serversocket; import java.io.ioexception; /* ---------- Java Server ---------- */ public class Nets static Socket thesocket; static ServerThread
More informationUser interfaces and Swing
User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends
More informationISO-2022-JP (JIS ) 1 2. (Windows95/98 MacOS ) Java UNICODE UNICODE. Java. .java.java.txt native2ascii. .java
2000 8 2000.1.24-27 0 4 1 ( (1 8 ) ASCII 1 8 1 1 8 2 ISO-2022-JP (JIS ) 1 2 EUC ( EUC) 8 Unix SJIS (MS ) EUC 8 ( (Windows95/98 MacOS Java UNICODE UNICODE ( Java.java.java.txt native2ascii.java native2ascii
More information/ Download the Khateeb Classes App
Q) Write a program to read and display the information about a book using the following relationship. Solution: import java.io.*; class Author String name,nationality,s; InputStreamReader r = new InputStreamReader(System.in);
More informationCS212 Midterm. 1. Read the following code fragments and answer the questions.
CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");
More informationLe L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading
Course Name: Advanced Java Lecture 7 Topics to be covered Multithreading Thread--An Introduction Thread A thread is defined as the path of execution of a program. It is a sequence of instructions that
More information* * * * * int i,j,k,line; for(i=1;i<=8;i++) { System.out.print("\n"); for(k=10-i;k>0;k--) { System.out.print(' '); }
/*************************************************************************************************************** Practical No:- Title :- Program to print the following sequence of stars. * * * * * * *
More information) / Java ( )
2002 3 2003.1.29 1 3 ( ) ( ) / Java ( ) 1 ( )? ( ) 2 (3 ) 3 Java Java Java (dynamic dispatch) ( ) import java.awt.*; import java.awt.event.*; public class Sample30 extends Frame { boolean go; double time;
More informationBufferedReader br = new BufferedReader(new InputStreamReader(System.in));
2.A. Design a superclass called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract
More informationUniversity of Palestine. Mid Exam Total Grade: 100
First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int
More informationNetbeans tutorial:
COE808 Lab2 Prelab preparation Before coming to the lab you should: 1. Read the lab. The most recent version can be found at the URL: www.ee.ryerson.ca/~courses/coe808 2. Try to prepare any questions you
More informationCS Computers & Programming I Review_01 Dr. H. Assadipour
CS 101 - Computers & Programming I Review_01 Dr. H. Assadipour 1. What is the output of this program? public class Q_01 public static void main(string [] args) int x=8; int y=5; double z=12; System.out.println(y/x);
More informationCSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name
CSC 1051 Algorithms and Data Structures I Final Examination May 12, 2017 Name Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces provided.
More informationL4,5: Java Overview II
L4,5: Java Overview II 1. METHODS Methods are defined within classes. Every method has an associated class; in other words, methods are defined only within classes, not standalone. Methods are usually
More informationModule Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are
More informationSpecial Exercise Unit: Introduction to Java
Special Exercise Unit: Introduction to Java Introduction First Program / Applet : Hello World Java Virtual Machine Java Basics (types, operators, statements, etc.) Object Orientation Standard Libraries
More informationCOE 212 Engineering Programming. Welcome to the Final Exam Monday May 18, 2015
1 COE 212 Engineering Programming Welcome to the Final Exam Monday May 18, 2015 Instructors: Dr. Joe Tekli Dr. George Sakr Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.
More informationVidyalankar. T.Y. Diploma : Sem. V [CO/CM/IF] Java Programming Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 100
T.Y. Diploma : Sem. V [CO/CM/IF] Java Programming Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 100 1. (a) (i) FEATURES OF JAVA 1) Compiled and interpreted 2) Platform independent and portable
More informationSorting and Searching
CHAPTER 13 Sorting and Searching The exercises in this chapter are a framework for comparing algorithms empirically. This approach provides students with a means for understanding the finer details of
More informationJava - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,
Java - Applets C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows
More informationOOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:
OOP Assignment V If we don t use multithreading, or a timer, and update the contents of the applet continuously by calling the repaint() method, the processor has to update frames at a blinding rate. Too
More information1 Definitions & Short Answer (5 Points Each)
Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work
More informationJava - Applets. public class Buttons extends Applet implements ActionListener
Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;
More informationCaesar Cipher program in java (SS)
Caesar Cipher program in java (SS) In cryptography Caesar cipher is one of the simple and most widely used Encryption algorithm.caesar cipher is special case of shift cipher.caesar cipher is substitution
More informationEE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS
Q1(a) Corrected code is: EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS 01 #include 02 using namespace std; 03 04 class Question1 05 06 int a,b,*p; 07 08 public: 09 Question1(int
More informationLecture 4 JAVA (46-935) Somesh Jha
Lecture 4 JAVA (46-935) Somesh Jha 1 Inner Classes Flashback totheabstracttermstructure class. There was a SlowYieldVolObject which computed: { (i = 0) Dierence between computed yield and the market yield
More information