int larger = max(30, 40);
System.out.println("Welcome to Java!");
public class TestMax {
/** 主方法 */
public static void main(String[] args) {
int i = 5;
int j = 2;
int k = max(i, j);
System.out.println("The maximum between " + i +
" and " + j + " is " + k);
}
/** 返回两个整数变量较大的值 */
public static int max(int num1, int num2) {
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
}
The maximum between 5 and 2 is 5
public class HelloWord {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="HelloWord!";
int a=0;
int b=a+1;
int result=0;
for(int i=0;i<20;i++)
{
//Add方法调用
result= Add(a,b);
System.out.println(str+" "+ result);
a+=i;
}
}
/**
* 被调用方法,这里使用了static声明为静态方法
* @param x
* @param y
* @return
*/
private static int Add(int x,int y)
{
return x+y;
}
}
public class HelloWord {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="HelloWord!";
int a=0;
int b=a+1;
int result=0;
for(int i=0;i<20;i++)
{
//Add方法调用
//类的实例化
HelloWord helloword=new HelloWord();
//通过实例化的类进行Add方法调用
result=helloword.Add(a, b);
System.out.println(str+" "+ result);
a+=i;
}
}
/**
* 被调用方法,没被static修饰,不是静态方法。调用时需要通过类的实例化进行调用
* @param x
* @param y
* @return
*/
private int Add(int x,int y)
{
return x+y;
}
}
public class Test {
/**
* 被调用方法Add
* @param x
* @param y
* @return
*/
public int Add(int x,int y)
{
return x+y;
}
/**
* 被调用方法Sub
* @param x
* @param y
* @return
*/
public static int Sub(int x,int y)
{
return x-y;
}
}
public class HelloWord {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="HelloWord!";
int a=5;
int b=a+1;
int result=0;
for(int i=0;i<20;i++)
{
//Add方法调用
//类的实例化
Test test=new Test();
//通过实例化的类进行Add方法调用
result=test.Add(a, b);
System.out.println(str+" "+ result);
result=test.Sub(b, 1);
System.out.println(str+" "+ result);
a+=i;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有