public static void main( String args[] )
{ int a = 5;
System.out.println( cube( a ) );
}
static int cube( int theNum )
{
return theNum * theNum * theNum;
}
===========================================
int dayhigh[] = { 24,23,24,25,25,23,21 };
int[] dayhigh = { 24,23,24,25,25,23,21 };
===================================================
int[]a[] = new int[5][5];==================================
If val = 1 in the code below:
switch( val )
{ case 1: System.out.print( "P" ); //break;
case 2:
case 3: System.out.print( "Q" );
break;
case 4: System.out.print( "R" );
default: System.out.print( "S" );
} 结果:PQ 有 break;结果:P 若val=100 结果:S
==========================================
the FileOutputStream constructor:
FileOutputStream(FileDescriptor fd)
FileOutputStream(String n, boolean a)
FileOutputStream(File f)
===============================================
class Base {
public void method(int i) {
System.out.println("Value is " + i);
}
}
public class Sub extends Base {
public void method(int j) {
System.out.println("This value is " + j);
}
public void method(String s) {
System.out.println("I was passed " + s);
}
public static void main(String args[]) {
Base b1 = new Base();
Base b2 = new Sub();
b1.method(5);
b2.method(6);
}
}
结果:Value is 5
This value is 6
本文通过几个具体的Java代码示例,展示了如何实现数值运算、数组操作、文件流创建及面向对象编程等基本功能。其中包括计算立方值、初始化数组、使用switch语句进行条件判断以及子类覆盖父类方法的实例。
1265

被折叠的 条评论
为什么被折叠?



