Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

3 Main

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

3 main

package package1;

public class Myclass {

public static void main(String[]args)

int n=Integer.parseInt(args[0]);

int res=factorial(n);

System.out.println(res);

protected static int factorial(int x) {

int res=1;

for(int i=x;i>1;i--) {

res=res*1;

return res;

--------------------------------------------------------------------------------------

package package1;

import java.util.Scanner;

public class Mycls extends Myclass {

public static void main(String[]args)

Scanner sc= new Scanner(System.in);

System.out.println("value");
int n=sc.nextInt();

int res=factorial(n);

System.out.println(res);

public static int factorial (int x) {

int res=1;

for(int i=x;i>=1;i--)

res=res*i;

return res;

------------------------------------------------------------------

4)1)

Main

package Package01;

import java.util.Scanner;

class Account {

private int id;

private double balance;

public boolean setid(int i)

if(i>0)

id=i;

return true;

}
else

return false;

public boolean setbalance(double b)

if(b>0)

balance=b;

return true;

else

return false;

public int getid()

return id;

public double getbalance()

return balance;

public double withdraw(double w)

balance=balance-w;

return w;

}
public double deposite(double d)

balance=balance+d;

return d;

public double printData()

return balance;

--------------------------------

package Package01;

import java.util.Scanner;

public class Demo {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

Account a=new Account();

int id;

double balance;

System.out.println("enter id,balance");

int i=sc.nextInt();

double b=sc.nextDouble();

if(a.setid(i)&&a.setbalance(b))

System.out.println("withdraw amount");
double w=sc.nextDouble();

a.withdraw(w);

System.out.println(a.printData());

System.out.println("how much to deposite");

double d1= sc.nextDouble();

a.deposite(b);

System.out.println(a.printData());

else

System.out.println("give valied value");

4)2)package Math;

public class MyPointDemo {

public static void main(String[] args) {

MyPoint p1=new MyPoint();

System.out.println(p1);

System.out.println(p1.distance(10,30.5));

MyPoint p2=new MyPoint(10,35);

System.out.println(p2);

System.out.println(p1.distance(p2));
}

package Math;

public class MyPoint {

private double x,y;

public MyPoint()

this.x=0;

this.y=0;

public MyPoint(double x, double y)

this.x=x;

this.y=y;

public double distance(double x,double y)

return Math.sqrt((this.x - x) * (this.x - x) + (this.y - y) * (this.y - y));

public double distance(MyPoint p)

return Math.sqrt((this.x - x) * (this.x - x) + (this.y - y) * (this.y - y));

}
public String toString()

String s;

s=String.format("point(%.2f,%.2f)",this.x,this.y);

return s;

You might also like