Question 1
Question 1
import java.util.Scanner;
public class Prime
{
private int n;
if (isPrime)
System.out.println("Prime Number");
else
System.out.println("Not a Prime Number");
}
-----------------------------------------------------------------------------------
--------------------
Question 2
Member functions:
Use a main function to create an object and call member methods of the class.
import java.util.Scanner;
---------------------------------------------------------------------
Question 3
Member functions:
import java.util.Scanner;
-----------------------------------------------------------------
In the following example, Human.java class has variables height, weight and bmi
which are private. For each variable, there is a setter and getter.
package com.tutorialkart.java;
/**
* @author tutorialkart
*/
class Human{
private float weight;
private float height;
private float bmi;
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getBmi() {
return bmi;
}
public void setBmi(float bmi) {
this.bmi = bmi;
}
}
--------------------------------------------------------------------------