Java Programs: Character Frequency, Inheritance, Palindrome, Matrix Multiplication & Polymorphism
Classified in Computers
Written at on English with a size of 5.03 KB.
Character Frequency
FREQUENCY
import java.util.Scanner;
class Test2 {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
System.out.print("ENTER THE STRING:");
String abc = s.nextLine();
System.out.println("Enter The Character for checking:");
char ch = s.nextLine().charAt(0);
int count = 0;
for(int i = 0; i < abc.length(); i++) {
if(ch == abc.charAt(i)) {
count++;
}
}
System.out.println("The given character repeats " + count + " times");
} }
OUTPUT
ENTER THE STRING: MALAYALAM
Enter The Character for checking:
M
The given character repeats 2 times
Inheritance Example
import java.util.Scanner;
class Employee {
String name = "Name";
String address = "Address";
int age = 23, phn_no = 123456789, salary = 500000;
void printsalary() {
System.out.println(