0% found this document useful (0 votes)
13 views2 pages

Set A

Uploaded by

souvik.it222073
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)
13 views2 pages

Set A

Uploaded by

souvik.it222073
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
You are on page 1/ 2

1.Write a Java program to print the result of the following operations.

Test Data:
a. -5 + 8 * 6
b. (55+9) % 9
c. 20 + -3*5 / 8
d. 5 + 15 / 3 * 2 - 8 % 3

public class Operations {


public static void main(String[] args) {
float a = -5.0f + 8 * 6;
float b = (55.0f + 9) % 9;
float c = 20.0f + -3 * 5 / 8.0f;
float d = 5 + 15 / 3.0f * 2 - 8 % 3;

System.out.println("Result of a: " + a);


System.out.println("Result of b: " + b);
System.out.println("Result of c: " + c);
System.out.println("Result of d: " + d);
}
}

2.Create a class 'Student' with three data members which are name, age and address.
The constructor of the class assigns default values name as "unknown", age as '0' and
address as "not available". It has two members with the same name 'setInfo'.
First method has two parameters for name and age and assigns the same whereas the second
method takes has three parameters which are assigned to name, age and address respectively.
Print the name, age and address of 10 students.

class Student {
String name;
int age;
String address;

public Student() {
this.name = "unknown";
this.age = 0;
this.address = "not available";
}

public void setInfo(String name, int age) {


this.name = name;
this.age = age;
}

public void setInfo(String name, int age, String address) {


this.name = name;
this.age = age;
this.address = address;
}

public void displayInfo() {


System.out.println("Name: " + name + ", Age: " + age + ", Address: " + address);
}
}
public class Main {
public static void main(String[] args) {
Student[] students = new Student[10];

for (int i = 0; i < students.length; i++) {


students[i] = new Student();
}

students[0].setInfo("Jack", 20);
students[1].setInfo("Oggy", 22, "123 Maple Street");
students[2].setInfo("Bheem", 19, "456 Oak Avenue");
students[3].setInfo("Doraemon", 21);
students[4].setInfo("Jon", 23, "789 Pine Road");

for (Student student : students) {


student.displayInfo();
}
}
}

You might also like