Practical File CJP Harshil
Practical File CJP Harshil
INDUS UNIVERSITY
Indus Institute of Technology and Engineering
Lab manual of
Core Java Programming
(CE0421)
INDEX
Sr. Aim Page Date Sign
No No.
3.3 Create a String Buffer with some default string. Append any 11
string to ith position of original string and display the
modified string. Also display the reverse of modified string.
Output:
int a, cnt = 0;
System.out.print("Enter the Number for which you want to check prime or not: ");
a = sc.nextInt();
if (cnt == 0) {
System.out.println(a + " is a prime!");
} else {
System.out.println(a + " is not a prime!");
}
}
}
Output:
Practical-1
1.3 Write a program to find a greater number among given three numbers using
a) ternary operator
b) nested if.
a)
public class prac1_3 {
public static void main(String[] args)
{
if (a > b) {
if (a > b)
System.out.println(a + " is greater");
else if (a < c)
System.out.println(c + " is greater");
} else if (b > a) {
if (b > c)
System.out.println(b + " is greater");
else if (c > b)
System.out.println(c + " is greater");
}
}
}
Output:
import java.util.Scanner;
int num, a = 0, b = 1, c;
System.out.println("---------------------------");
num = sc.nextInt();
c = a + b;
a = b;
b = c;
} } }
Output:
arr[i] = sc.nextInt();
sum += arr[i];
}
System.out.println("AVERAGE = " + (sum / size));
} }
Output:
Practical-3
3.1 WAP to replace substring with other substring in the given string.
a = a.replace(b, c);
Output:
Output:
Practical-3
3.3 Create a String Buffer with some default string. Append any string to ith position of original
string and display the modified string. Also display the reverse of modified string.
Output:
class person {
int age, salary;
String name;
}
Output:
Practical-4
4.1.2 Add a constructor to the Person class developed above.
File Name: prac4_1_.java
import java.util.Scanner;
class person {
Scanner s = new Scanner(System.in);
int age, salary;
String name;
person() {
System.out.print("Enter name: ");
name = s.nextLine();
System.out.print("Enter age: ");
age = s.nextInt();
System.out.print("Enter salary: ");
salary = s.nextInt();
}
}
Output: