(ref T position, float offset, float scale){
Type vector = position.GetType();
MethodInfo add = vector.GetMethod("op_Addition", new[] {typeof(T), typeof(T)});
MethodInfo multiply = vector.GetMethod("op_Multiply", new[] {typeof(T), typeof(float)});
T one = (T) vector.GetProperty("one").GetValue(null);
position = (T) add.Invoke(null, new object[] {position, multiply.Invoke(null, new object[] {one, offset + 0.1f})});
position = (T) multiply.Invoke(null, new object[] {position, scale});
}
Shakllar yuzasini hisoblash
Aylana:
class AreaOfCircle
{
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
System.out.println("Enter the radius:");
double r= s.nextDouble();
double area=(22*r*r)/7 ;
System.out.println("Area of Circle is: " + area);
}
}
Konus:
package SurfaceAreaPrograms;
import java.util.Scanner;
public class VolumeOfCone {
private static Scanner sc;
public static void main(String[] args) {
double radius, height;
// LSA = Lateral Surface Area of a Cone, SA = Surface Area
double length, SA, Volume, LSA;
sc = new Scanner(System.in);
System.out.println("\n Please Enter the Radius of a Cone : ");
radius = sc.nextDouble();
System.out.println("\n Please Enter the Height of a Cone : ");
height = sc.nextDouble();
length = Math.sqrt(radius * radius + height * height);
SA = Math.PI * radius * (radius + length);
Volume = (1.0/3) * Math.PI * radius * radius * height;
LSA = Math.PI * radius * length;
System.out.format("\n The Length of a Side (Slant)of a Cone = %.2f", length);
System.out.format("\n The Surface area of a Cone = %.2f", SA);
System.out.format("\n The Volume of a Cone = %.2f", Volume);
System.out.format("\n The Lateral Surface area of a Cone = %.2f", LSA);
}
}
Silindr:
package org.arpit.java2blog;
import java.util.Scanner;
public class TotalSurfaceAreaCylinderMain {
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
System.out.println("Enter the radius of cylinder :");
double r=s.nextDouble();
System.out.println("Enter the height of cylinder :");
double h=s.nextDouble();
double surfaceAreaOfCylinder= 2 * Math.PI * r * r + 2 * Math.PI * r * h;
System.out.println("Total surface area of cylinder is: "+surfaceAreaOfCylinder);
s.close();
}
}
Generic Class
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
interface SomeContainer {
E createContents();
}
public class Main {
@SuppressWarnings("unchecked")
public static SomeContainer createSomeContainer() {
return (SomeContainer) Proxy.newProxyInstance(Main.class.getClassLoader(),
new Class[]{ SomeContainer.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Class> returnType = method.getReturnType();
return returnType.newInstance();
}
});
}
public static void main(String[] args) {
SomeContainer container = createSomeContainer();
[*] System.out.println("String created: [" +container.createContents()+"]");
}
}