您好,欢迎访问一九零五行业门户网

Java程序展示方法的嵌套

nesting of methods is a hybrid function calling method in java, which can call another method in the same class. there are two types of nested classes are available in a java environment.
将方法嵌套视为java中的混合函数调用方法,它可以调用同一类中的另一个方法。在java环境中有两种类型的嵌套类可用非静态嵌套类(也称为内部类)
静态嵌套类
一个非静态嵌套类(或者内部类)是在一个特定类内定义的类。它还包含一些具有一些访问权限的外部类。在这种方法中,我们可以使用“.”运算符通过使用外部类来创建内部类的实例。
另一方面,静态嵌套类是在类内部创建的特定类。但是这种类型的嵌套类无法访问任何非静态的方法和成员。它们只能被外部类访问。
在今天的文章中,我们将学习java虚拟机环境中存在的各种嵌套方法。并且我们将使用下面提到的语法和算法编写一些可能的代码。
在java中显示嵌套方法的算法在这个可能的算法中,我们将学习嵌套方法在java环境中的实际工作原理。通过按照这些步骤,我们将根据问题陈述构建一些java代码。
第一步 - 开始。
第二步 - 输入数据样本。
第三步 - 初始化输入权重。
第四步 - 初始化隐藏节点的偏置。
第五步 - 选择一个函数进行定义。
步骤6 - 如果方法满足逻辑,则继续。
步骤7 - 否则,返回第三步和第四步。
步骤8 - 如果该方法符合代码要求,则选择隐藏节点的最佳输入权重和偏置。
第9步 - 通过应用经验方法确定初始隐藏节点的数量。
第10步 - 确定最佳隐藏节点数量。
第11步 - 训练样本。
第12步 - 如果准确度达到标记,则终止该过程。
第13步 - 获取嵌套模型。
第14步 - 进行所有预测。
步骤15 - 否则,再次根据经验方法确定隐藏节点的初始数量。
显示方法嵌套的语法process syntax:
class main { method1(){ } method2(){ method1(); } method3(){ method2(); }}
class syntax:
class outerclass { // ... class nestedclass { // ... }}
嵌套方法使用java语法:
class nesting2001{ int m, n; nesting2001 (int x, int y){ m=x; n=y; } int largest ( ){ if (m >=n) return(m); else return(n); } void display( ){ int large=largest ( ); system.out. println(largest value is here large); }}class nestmain2022{ public static void main ( string args[ ]){ nesting2001 nest=new nesting2001 (10, 20); nest. display( ); }}
在这个可能的语法中,我们尝试展示如何构建一个java代码来解释和展示各种嵌套方法。
展示不同嵌套方法的途径使用java的嵌套方法找到球的面积
通过在java中调用main()和swap()方法找到两个数字的总和
approach 3 − java程序展示嵌套方法以找到周长值
方法4 - java内部类和嵌套类
通过使用三个方法类显示嵌套方法的java程序
使用java的嵌套方法来计算球体的面积让我们使用java的嵌套方法来计算球体的面积。这里我们使用了两个类,包含area()和volume(),用于计算球体的面积和体积。
example 1public class nesting2022 { public void area(double r){ system.out.println(##### inside area method will be applied #####); double a = 7 * math.pi * r * r; system.out.println(surface area of the particular sphere is : + a); } public void volume(double r){ system.out.println(%%%%% inside volume method will be applied here%%%%%); double v = (4 / 3) * math.pi * r * r * r; system.out.println(volume of a sphere is here : + v); } public static void main(string args[]){ nesting2022 rddarb = new nesting2022(); rddarb.area(12); rddarb.volume(12); }}
输出##### inside area method will be applied #####surface area of the particular sphere is : 3166.7253948185116%%%%% inside volume method will be applied here%%%%%volume of a sphere is here : 5428.672105403162
通过调用main()和swap()方法来对两个数字进行相加:在这段java代码中,我们尝试通过调用main()和swap()方法来展示两个数字的相加过程。
example 2的中文翻译为:示例2public class nesting1997 { public void swap(int x, int y){ system.out.println(**@@$$%%this is a swap method. lets check the process%%$$@@**); system.out.println(before swapping the condition:x= + x + + y= + y); int z = x; x = y; y = z; system.out.println(after swapping the condition:a= + x + + b= + y); } public void tutorialspoint16 (int a, int b){ system.out.println(#####this is tutorialspoint16 encoded method#####); system.out.println(before performing the operation we will get:a= + a + + b= + b); a = a + 10; b = b + 12; system.out.println(after operation, the system will return:a= + a + + b= + b); swap(a, b); } public static void main(string args[]){ nesting1997 tutorialspoint07 = new nesting1997(); int a = 20, b = 30; tutorialspoint07.tutorialspoint16(a, b); }}
输出#####this is tutorialspoint16 encoded method#####before performing the operation we will get:a=20 b=30after operation, the system will return:a=30 b=42**@@$$%%this is a swap method. lets check the process%%$$@@**before swapping the condition:x=30 y=42after swapping the condition:a=42 b=30
嵌套方法以找出周长值在这段java代码中,我们尝试展示方法的嵌套来找出周长的值。
example 3的中文翻译为:示例3import java.util.scanner;public class nestingbycuboid2023{ int perimeter(int l, int b){ int pr = 12 * (l + b); return pr; } int area(int l, int b){ int pr = perimeter(l, b); system.out.println(perimeter:+pr); int ar = 6 * l * b; return ar; } int volume(int l, int b, int h){ int ar = area(l, b); system.out.println(area:+ar); int vol ; vol = l * b * h; return vol; } public static void main(string[] args) { scanner s = new scanner(system.in); system.out.print(enter length of that particular cuboid:); int l = s.nextint(); system.out.print(enter breadth of that particular cuboid:); int b = s.nextint(); system.out.print(enter height of that particular cuboid:); int h = s.nextint(); nesting_methods obj = new nesting_methods(); int vol = obj.volume(l, b, h); system.out.println(volume:+vol); }}
输出enter length of that particular cuboid:7enter breadth of that particular cuboid:16enter height of that particular cuboid:10perimeter:276area:672volume:1120
java内部类和嵌套类在这个例子中,我们可以演示如何在java环境中声明一些内部类和嵌套类。
示例4//java code to define an inner class we can use in jvmclass cpuz { double price; class processor{ double cores; string manufacturer; double getcache(){ return 16.10; } } protected class ram{ double memory; string manufacturer; double getclockspeed(){ return 07.10; } }}public class main { public static void main(string[] args) { cpuz cpu = new cpuz(); cpuz.processor processor = cpu.new processor(); cpuz.ram ram = cpu.new ram(); system.out.println(processor cache we will get = + processor.getcache()); system.out.println(ram clock speed we can examine = + ram.getclockspeed()); }}
输出processor cache we will get = 16.1ram clock speed we can examine = 7.1
example 4 a的翻译为:示例 4 a//java code to access membersclass car2022 { string carname; string cartype; public car2022(string name, string type) { this.carname = name; this.cartype = type; } private string getcarname() { return this.carname; } class engine { string enginetype; void setengine() { if(car2022.this.cartype.equals(7xyxarb)){ if(car2022.this.getcarname().equals(crysler)) { this.enginetype = smaller engine type; } else { this.enginetype = bigger engine type; } }else{ this.enginetype = bigger engine type; } } string getenginetype(){ return this.enginetype; } }}public class main { public static void main(string[] args) { car car1 = new car(mazda, 16xyzarb); car.engine engine = car1.new engine(); engine.setengine(); system.out.println(engine type for 16xyzrdd= + engine.getenginetype()); car car2 = new car(crysler, 7xyzarb); car.engine c2engine = car2.new engine(); c2engine.setengine(); system.out.println(engine type for 7xyzarb = + c2engine.getenginetype()); }}
输出engine type for 16xyzrdd= bigger engine typeengine type for 7xyzarb = bigger engine type
example 4b//java program to demonstrate a static inner class using jvmclass mbcss { static class usb2022{ int usb2 = 2; int usb3 = 1; int gettotalports(){ return usb2 + usb3; } }}public class main { public static void main(string[] args) { mbcss.usb2022 usb = new mbcss.usb2022(); system.out.println(total ports present here in the system = + usb.gettotalports()); }}
输出total ports present here in the system = 3
java程序通过使用三层方法类来展示嵌套方法在这个例子中,我们编写了一个特定的java代码方法,使用三重方法类来展示嵌套过程。在这里,一个特定的方法可以调用任意的随机方法。在这里也可以调用另一个方法。这意味着,方法1可以调用方法2,方法2的返回值可以调用方法3。
example 5的翻译为:示例5public class nesting0{ public void a1(int a, int b){ a = a + 10; b = b + 20; system.out.println( ******#### inside the a1 method ####******); system.out.println(a = + a + + b = + b); a2(a, b); } public void a2(int x, int y){ x = x + 100; y = y + 200; system.out.println( ******@@@ inside the a2 method @@@******); system.out.println(x = + x + + y = + y); } public void a3(int w, int z){ w = w + 50; z = z - 50; system.out.println( ******%% inside the a3 method %%******); system.out.println(w = + w + + z = + z); a1(w, z); } public static void main(string[] args){ nesting0 arbrdd = new nesting0(); int a = 100, b = 200; arbrdd.a3(a, b); }}
输出******%% inside the a3 method %%******w = 150 z = 150******#### inside the a1 method ####******a = 160 b = 170******@@@ inside the a2 method @@@******x = 260 y = 370
结论在这里,我们讨论了嵌套方法,并通过遵循语法和算法提供了一些可能的java代码。希望本文能帮助您理解这里提到的各种嵌套方法的操作方式。
以上就是java程序展示方法的嵌套的详细内容。
其它类似信息

推荐信息