0% found this document useful (0 votes)
8 views8 pages

Java Programs

The document contains a series of Java programs that perform various tasks, including storing and displaying student remarks based on average marks, calculating subject averages, printing elements ending with 3, and merging arrays. It also includes programs for finding common elements in two arrays, searching for wonders by country, food crop production, and searching names and phone numbers in a phone book. Each program is structured with user input and output to demonstrate its functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Java Programs

The document contains a series of Java programs that perform various tasks, including storing and displaying student remarks based on average marks, calculating subject averages, printing elements ending with 3, and merging arrays. It also includes programs for finding common elements in two arrays, searching for wonders by country, food crop production, and searching names and phone numbers in a phone book. Each program is structured with user input and output to demonstrate its functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Programs

1. Program to Store and Display Remarks Based on Average Marks

import [Link];

class SM {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter number of students: ");


int n = [Link]();

int r[] = new int[n];


String nm[] = new String[n];
int m1[] = new int[n], m2[] = new int[n], m3[] = new int[n];

for (int i = 0; i < n; i++) {


[Link]("Enter details for student " + (i + 1) + ":");
[Link]("Roll: ");
r[i] = [Link]();
[Link]();
[Link]("Name: ");
nm[i] = [Link]();
[Link]("Marks1: ");
m1[i] = [Link]();
[Link]("Marks2: ");
m2[i] = [Link]();
[Link]("Marks3: ");
m3[i] = [Link]();
}

[Link]("\nResults:");
for (int i = 0; i < n; i++) {
int avg = (m1[i] + m2[i] + m3[i]) / 3;
String rm;
if (avg >= 85) rm = "EXCELLENT";
else if (avg >= 75) rm = "DISTINCTION";
else if (avg >= 60) rm = "FIRST CLASS";
else if (avg >= 40) rm = "PASS";
else rm = "POOR";
[Link]("Roll: " + r[i] + ", Name: " + nm[i] + ", Avg: " + avg + ", Remark: " +
rm);
}
}
}

2. Program to Calculate Subject Average, Highest Mark, and Student Name

import [Link];

class SA {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

String nm[] = new String[50];


int m[] = new int[50];
int t = 0, h = 0;
String ts = "";

for (int i = 0; i < 50; i++) {


[Link]("Enter details for student " + (i + 1) + ":");
[Link]("Name: ");
nm[i] = [Link]();
[Link]("Marks: ");
m[i] = [Link]();
[Link]();

t += m[i];
if (m[i] > h) {
h = m[i];
ts = nm[i];
}
}

double avg = (double) t / 50;


[Link]("\nSubject Average: " + avg);
[Link]("Highest Mark: " + h + " by " + ts);
}
}
3. Program to Print Elements Ending with 3

import [Link];

class EW {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int a[] = new int[10];


[Link]("Enter 10 elements:");
for (int i = 0; i < 10; i++) {
a[i] = [Link]();
}

[Link]("Elements ending with 3:");


for (int i = 0; i < 10; i++) {
if (a[i] % 10 == 3) {
[Link](a[i] + " ");
}
}
}
}

4. Program to Print First Letters of Color Names

import [Link];

class CN {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

String cr[] = new String[7];


[Link]("Enter 7 color names:");
for (int i = 0; i < 7; i++) {
cr[i] = [Link]();
}

[Link]("First letters:");
for (int i = 0; i < 7; i++) {
[Link](cr[i].charAt(0) + " ");
}
}
}

5. Program to Merge Two Arrays

import [Link];

class MergeArrays {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int p[] = new int[6];


int q[] = new int[4];
int r[] = new int[10];

[Link]("Enter 6 elements for array P:");


for (int i = 0; i < 6; i++) {
p[i] = [Link]();
}

[Link]("Enter 4 elements for array Q:");


for (int i = 0; i < 4; i++) {
q[i] = [Link]();
}

for (int i = 0; i < 6; i++) {


r[i] = p[i];
}
for (int i = 0; i < 4; i++) {
r[i + 6] = q[i];
}

[Link]("Merged Array R:");


for (int i = 0; i < 10; i++) {
[Link](r[i] + " ");
}
}
}

6. Program to Find Common Elements in Two Arrays

import [Link];
class CommonElements {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int tec[] = new int[8];


int the[] = new int[8];
int tin[] = new int[8];
int k = 0;

[Link]("Enter 8 elements for array TEC:");


for (int i = 0; i < 8; i++) {
tec[i] = [Link]();
}

[Link]("Enter 8 elements for array THE:");


for (int i = 0; i < 8; i++) {
the[i] = [Link]();
}

for (int i = 0; i < 8; i++) {


for (int j = 0; j < 8; j++) {
if (tec[i] == the[j]) {
tin[k++] = tec[i];
break;
}
}
}

[Link]("Array TEC:");
for (int i = 0; i < 8; i++) {
[Link](tec[i] + " ");
}

[Link]("\nArray THE:");
for (int i = 0; i < 8; i++) {
[Link](the[i] + " ");
}

[Link]("\nCommon Elements (TIN):");


for (int i = 0; i < k; i++) {
[Link](tin[i] + " ");
}
}
}

7. Program to Search Wonders by Country

import [Link];

class Wonders {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

String wonders[] = {"CHICHEN ITZA", "CHRIST THE REDEEMER", "TAJ MAHAL",


"GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA", "COLOSSEUM"};
String loc[] = {"MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU", "JORDAN", "ITALY"};

[Link]("Enter country name: ");


String cn = [Link]().toUpperCase();

boolean found = false;


for (int i = 0; i < 7; i++) {
if (loc[i].equals(cn)) {
[Link]("Wonder: " + wonders[i]);
found = true;
break;
}
}

if (!found) {
[Link]("Sorry, not found!");
}
}
}

8. Program to Search for Food Crop Production

import [Link];

class FoodCrops {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

String fc[] = {"Apple", "Banana", "Cabbage", "Coffee", "Maize"};


int fp[] = {84743988, 112627980, 69790058, 9353937, 1126990585};
[Link]("Enter the name of the crop: ");
String crop = [Link]();

boolean found = false;


for (int i = 0; i < 5; i++) {
if (fc[i].equalsIgnoreCase(crop)) {
[Link]("Annual Production of " + crop + ": " + fp[i] + " metric ton");
found = true;
break;
}
}

if (!found) {
[Link]("Crop not found!");
}
}
}

9. Program to Search Name and Phone Number

import [Link];

class PhoneBook {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

String nm[] = {"John", "Alice", "Bob", "Daisy", "Mark"};


String ph[] = {"12345", "67890", "54321", "98765", "11223"};

[Link]("Enter name to search: ");


String name = [Link]();

boolean found = false;


for (int i = 0; i < 5; i++) {
if (nm[i].equalsIgnoreCase(name)) {
[Link]("Search successful!");
[Link]("Name: " + nm[i] + ", Phone: " + ph[i]);
found = true;
break;
}
}
if (!found) {
[Link]("Search unsuccessful. Name not enlisted.");
}
}
}

You might also like