Professional Documents
Culture Documents
Java PDF To Word
Java PDF To Word
Index
Sr.
no Date Practical Grade Signature
1|P a g e
180160107018 OOP-1(3140705)
8 Write a program that reads an integer and
displays all its smallest factors in increasing
order. For example if input number is 120, the
output should be as follows:2,2,2,3,5.
9 Write a method with following method header.
public static int gcd(int num1, int num2)
Write a program that prompts the user to enter
two integers and compute the gcd of two
integers.
10 Write a test program that prompts the user to
enter ten numbers, invoke a method to reverse
the numbers, display the numbers.
11 Write a program that generate 6*6 two-
dimensional matrix, filled with 0’s and 1’s ,
display the matrix, check every raw and column
have an odd number’s of 1’s.
12 Write a program that creates a Random object
with seed 1000 and displays the first 100
random integers between 1 and 49 using the
NextInt (49) method.
13 Write a program for calculator to accept an
expression as a string in which the operands and
operator are separated by zero or more spaces.
For ex:3+4 and 3 + 4 are acceptable expressions.
14 Write a program that creates an Array List and
adds a Loan object , a Date object , a string, and
a Circle object to the list, and use a loop to
display all elements in the list by invoking the
object’s to String() method.
15 Write the bin2Dec (string binary String) method
to convert a binary string into a decimal number.
Implement the bin2Dec method to throw a
NumberFormatException if the string is not a
Binary string.
16 Write a program that prompts the user to enter
a
decimal number and displays the number in a
fraction.
Hint: Read the decimal number as a string,
extract the integer part and fractional part from
the string.
2|P a g e
180160107018 OOP-1(3140705)
17 Write a program that displays a tic-tac-toe
board.
A cell may be X, O, or empty.What to display
at each cell is randomly decided.The X and O
are images in the files X.gif and O.gif.
18 Write a program that moves a circle up, down,
left or right using arrow keys.
19 Write a program that displays the color of a
circle as red when the mouse button is pressed
and as blue when the mouse button is released.
20 Write a GUI program that use button to move
the message to the left and right and use the
radio button to change the color for the message
displayed.
21 Write a program to create a file name 123.txt, if
it does not exist. Append a new data to it if it
already exist. write 150 integers created
randomly into the file using Text I/O. Integers
are separated by space.
22 Write a recursive method that returns
the smallest integer in an array. Write a
test program that prompts the user to
enter an integer and display its product.
23 Write a generic method that returns the
minimum elements in a two dimensional
array.
24 Define MYPriorityQueue class that extends
Priority Queue to implement the Cloneable
interface and implement the clone() method
to clone a priority queue.
25 Write a program that reads words from a
text file and displays all the nonduplicate
words in descending order.The text file is
passed as a command-line argument.
3|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:1
Program:
class P1_019
{
public static void main(String args[])
{
System.out.println("Welcome to Java,Learning
JavaNow,Programming is fun");
}
}
Output:
4|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:2
Program:
import java.util.*;
class P2_019
{
public static void main(String args[])
{
double a=3.4,b=50.2,e=44.5,c=2.1,d=0.55,f=5.9,x,y;
System.out.println("1) "+a+"X+"+b+"Y="+e);
System.out.println("2) "+c+"X+"+d+"Y="+f);
x=(e*d-b*f)/(a*d-b*c);
y=(a*f-e*c)/(a*d-b*c);
System.out.println("x:"+x);
System.out.println("y:"+y);
}
}
5|P a g e
180160107018 OOP-1(3140705)
Output:
6|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:3
Program:
import java.util.*;
class P3_019
{
public static void main(String args[])
{
double m,f;
System.out.println("Please enter meter");
Scanner sc=new Scanner(System.in);
m=sc.nextDouble();
f=m*(3.2808319);
System.out.println("feet:"+f);
}
}
Output:
7|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:4
Program:
import java.util.*;
class P4_019
{
public static void main(String args[])
{
double pound,kg,inches,meter,BMI;
System.out.println("enter weight in pound:");
Scanner sc=new Scanner(System.in);
System.out.println("enter height in inches:");
pound=sc.nextDouble();
inches=sc.nextDouble();
kg=pound/2.205;
meter=inches/39.39;
BMI=kg/(meter*meter);
System.out.println("height in meter:"+meter);
System.out.println("weight in kg:"+kg);
System.out.println("BMI:"+BMI);
}
}
8|P a g e
180160107018 OOP-1(3140705)
Output:
9|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:5
Program:
import java.util.*;
class P5_019
{
public static void main(String args[])
{
int i,j,max;
int a[]=new int[3];
Scanner sc=new Scanner(System.in);
System.out.println("please enter the value:");
a[0]=sc.nextInt();
a[1]=sc.nextInt();
a[2]=sc.nextInt();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i]>a[j])
{
max=a[i];
a[i]=a[j];
a[j]=max;
}
}
10
|P a g e
180160107018 OOP-1(3140705)
}
System.out.println("Decreasing order:");
for(i=0;i<3;i++)
{
System.out.println(a[i]);
}
}
}
Output:
11
|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:6
AIM: Write a program that prompts the user to enter a letter and
Check whether a letter is a vowel or constant.
Program:
import java.util.*;
class P6_019
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter any character from A-Z=");
char ch=sc.next().charAt(0);
if(ch=='a'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u'||
ch=='A'|| ch=='E'|| ch=='I'|| ch=='O'|| ch=='U')
{
System.out.println(ch+"=is vowel");
}
else
{
System.out.println(ch+"=is consonant");
}
}
}
12
|P a g e
180160107018 OOP-1(3140705)
Output:
13
|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:7
Program:
import java.util.*;
class P7_019
{
public static void main(String args[])
{
Random rd= new Random();
char temp;
StringBuffer str1= new StringBuffer();
StringBuffer str2= new StringBuffer();
for(int i=0;i<3;i++)
{
temp= (char)(rd.nextInt(26)+'A');
str1.append(temp);
}
for(int j=0;j<4;j++)
{
temp= (char)(rd.nextInt(10)+'0');
str2.append(temp);
}
StringBuffer str= new StringBuffer();
str= str1.append(str2);
14
|P a g e
180160107018 OOP-1(3140705)
System.out.println("Number plate generated is : ");
System.out.println(str);
}
}
Output:
15
|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:8
Program:
import java.util.*;
class P8_019
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Integer value :");
int number = sc.nextInt();
int index = 2;
while(number / index != 0)
{
if(number % index == 0)
{
System.out.println(index+" ");
number /= index;
}
else
{
index++ ;
}
16
|P a g e
180160107018 OOP-1(3140705)
}
}
}
Output:
17
|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:9
Program:
import java.util.*;
class P9_019
{
public static int gcd(int num1, int num2)
{
int gcd = 1;
for(int i=1;i<=num1 && i<=num2;i++)
{
if(num1%i==0 && num2%i==0)
{
gcd = i;
}
}
return gcd;
}
public static void main(String args[])
{
int answer=0;
int n1=0,n2=0;
Scanner sc = new Scanner(System.in);
18
|P a g e
180160107018 OOP-1(3140705)
System.out.print("enter value of number 1 = ");
n1 =sc.nextInt();
System.out.print("enter value of number 2 = ");
n2 =sc.nextInt();
answer = gcd(n1, n2);
System.out.print("answer is "+answer);
sc.close();
}
}
Output:
19
|P a g e
180160107018 OOP-1(3140705)
PRACTICAL:10
AIM: Write a test program that prompts the user to enter ten
Numbers, invoke a method to reverse the numbers,
Display the numbers.
Program:
import java.util.*;
class P10_19
{
public static void main(String args[])
{
int[] num1;
int[] num2;
num1 = new int[12];
num2 = new int[12];
Scanner sc=new Scanner(System.in);
System.out.println("Enter 10 Integer Numbers");
for(int i=1;i<=10;i++)
{
num1[i]=sc.nextInt();
}
for(int i=1,j=10;i<=10;i++,j--)
{
num2[j]=num1[i];
}
System.out.println("Reverse of your INPUT");
for(int i=1;i<=10;i++)
20
|P a g e
180160107018 OOP-1(3140705)
{
System.out.println(num2[i]+" ");
}
sc.close();
}
}
21
|P a g e
180160107018 OOP-1(3140705)
Output:
22
|P a g e