Non-Parametrized Functions
public class OOPSConcept {
int x,y;
void up()
{
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
System.out.print("*");
}
System.out.printf("\n");
}
}
void down()
{
int a,b;
for(a=1;a<=5;a++)
{
for(b=5;b>=a;b--)
{
System.out.print("*");
}
System.out.printf("\n");
}
}
public static void main(String[] args) {
OOPSConcept rishu= new OOPSConcept();
char x = 'u';
if(x=='u')
{
rishu.up();
}
else if (x=='d')
{
rishu.down();
}
else
{
System.out.println("Invalid Variable");
}
}
}
Parametrized Functions
STAR PRINTING
public class Oops2 {
int a,b;
void up(int c)
{
for(a=1;a<=c;a++)
{
for(b=1;b<=a;b++)
{
System.out.print("*");
}
System.out.print("\n");
}
}
void down(int c)
{
for (a=1; a<=c; a++)
{
for (b=c;b>=a;b--)
{
System.out.print("*");
}
System.out.print("\n");
}
}
public static void main(String []args){
Oops2 obj = new Oops2();
Oops2 obj1 = new Oops2();
obj.down(6);
obj1.up(6);
}
OTHER FUNCTIONS
int x;
void hi()
{
System.out.println("hello");
}
public static void main(String[] args) {
Oops2 Hello = new Oops2();
Hello.x=5;
Hello.hi();
System.out.println(Hello.x);
}
}
ARITHMETIC
void add(int a ,int b)
{
System.out.println(a+b);
}
void sub(int a, int b)
{
System.out.println(a-b);
}
void mul(int a, int b)
{
System.out.println(a*b);
}
void div(int a, int b)
{
System.out.println(a/b);
}
public static void main(String []args){
Oops2 obj = new Oops2();
obj.add(5,8);
}
Parametrised and Non Parametrised together
public class ParametrisedAndNonParametrised {
int x,y;
void add(){
System.out.printf("%d\n",x+y);
}
void sub(){
System.out.printf("%d\n",x-y);
}
void mul(int x, int y){
System.out.printf("%d\n",x*y);
}
void div(int x, int y){
System.out.printf("%d\n",x/y);
}
public static void main(String[] args) {
ParametrisedAndNonParametrised addsub = new ParametrisedAndNonParametrised();
addsub.x=10;
addsub.y=15;
char f= 'm';
if (f=='a')
{
addsub.add();
}
else if (f=='s')
{
addsub.sub();
}
else if (f=='m')
{
addsub.mul(10, 15);
}
else if (f=='d')
{
addsub.div(10, 15);
}
else
{
System.out.println("Invalid Variable");
}
}
Student data (Long)
public class Oops {
String name;
int id;
int fee;
public static void main(String[] args) {
Oops obj_name= new Oops();
obj_name.name = "RAJ";
System.out.printf("Student Name is %s\n",obj_name.name);
Oops obj_id = new Oops();
obj_id.id = 15;
System.out.printf("Raj's ID is %d\n", obj_id.id);
Oops obj_fees = new Oops();
obj_fees.fee = 3000;
System.out.printf("Raj's FEE is %d\n\n", obj_fees.fee);
/*****************************************/
/*obj_name.name = "SHYAM";
System.out.printf("Student Name is %s\n",obj_name.name);
obj_id.id = 17;
System.out.printf("Shyam's ID is %d\n", obj_id.id);
obj_fees.fee = 4000;
System.out.printf("Shyam's FEE is %d\n\n", obj_fees.fee);
/******************************************/
/*obj_name.name = "RAM";
System.out.printf("Student Name is %s\n",obj_name.name);
obj_id.id = 24;
System.out.printf("Ram's ID is %d\n", obj_id.id);
obj_fees.fee = 5000;
System.out.printf("Ram's FEE is %d\n\n", obj_fees.fee);
}
Student Data (Short)
public class Oops {
String name;
int id;
int fee;
int disc;
void insert(int i, int f, String n,int dis)
{
id = i;
fee = f;
name = n;
disc = dis;
}
void display()
{
System.out.printf("Student name is %s\n",name);
System.out.printf("%s ID is %d\n",name,id);
System.out.printf("%s FEE is %d\n",name,fee);
void discount2()
{
fee = (fee-fee*disc/100);
public static void main(String[] args) {
Oops raj = new Oops();
raj.insert(100, 1000, "Raj", 2);
raj.display();
raj.discount2();
System.out.println("\n\n");
System.out.println("After Discount his Fees is \n\n");
raj.display();
System.out.println("\n\n");
Oops ram = new Oops();
ram.insert(101, 2000, "Ram", 2);
ram.display();
ram.discount2();
System.out.println("\n\n");
System.out.println("After Discount his Fees is \n\n");
ram.display();
}
Banking
public class OOPSBAnking {
String name;
int acc;
int bal;
int with;
int dep;
void Input_Details(String name1, int acco, int balance)
{
name = name1;
acc = acco;
bal = balance;
}
void Display_Details()
{
System.out.printf("The name of account holder is %s\n", name);
System.out.printf("%s account number is %d\n",name, acc);
System.out.printf("%s account balance is %d\n",name, bal);
}
void withdraw(int withdraw)
{
with = withdraw;
bal = bal - with;
System.out.printf("%s withdrawed %d from his accunt \n",name, with);
System.out.printf("%s current account balance is %d\n",name,bal);
}
void deposit(int deposit)
{
dep = deposit;
bal = bal + dep;
System.out.printf("%s deposited %d in his accunt \n",name, dep);
System.out.printf("%s current account balance is %d\n",name, bal);
}
public static void main(String[] args) {
OOPSBAnking bank = new OOPSBAnking();
bank.Input_Details("Rishul", 76, 50000);
bank.Display_Details();
bank.withdraw(30000);
bank.deposit(10000);
/*int f = 'w';
if (f=='n')
{
bank.Display_Details();
}
else if(f=='w')
{
bank.withdraw(30000);
}
else if(f=='d')
{
bank.deposit(10000);
}
else
{
System.out.println("Invalid Variable");
}
*/