张孝祥《Java就业培训教程》源代码 02 部分
《Java就业培训教程》 作者:张孝祥 书中源码
《Java就业培训教程》P34源码
程序清单:Promote.java
class Promote
{
public static void main(String args[])
{
byte b = 50;
char c = 'a';
short s = 1024;
int i = 50000;
float f = 5.67f;
double d = .1234;
double result = (f * b) + (i / c) - (d * s);
System.out.println((f * b) + " + " + (i / c) + " - " + (d * s));
System.out.println("result = " + result);
}
}
《Java就业培训教程》P35源码
程序清单:TestScope.java
public class TestScope
{
public static void main(String[] args)
{
int x = 12;
{
int q = 96; // x和q都可用
System.out.println("x is "+x);
System.out.println("q is "+q);
}
q = x; /* 错误的行,只有x可用, q 超出了作用域范围 */
System.out.println("x is "+x);
}
}
《Java就业培训教程》P37源码
程序清单:TestVar.java
public class TestVar
{
public static void main(String [] args)
{
int x;//应改为int x=0;
x=x+1; //这个x由于没有初始化,编译会报错。
System.out.println("x is "+x);
}
}
程序清单:Func1.java
public class Func1
{
public static void main(String [] args)
{
/* 下面是打印出第一个矩形的程序代码*/
for(int i=0;i<3;i++)
{
for(int j=0;j<5;j++)
{
System.out.print("*");
&
相关文档:
public class P {
public static void main(String[] args){
String pattern="000";
java.text.DecimalFormat df = new java.text.DecimalFormat(pattern);
int i = 10,j=6;
System.out.println("i="+df.format(i)+"\nj="+df.format(j));
}
}
---------------------输出-----------------------
i=010 ......
Java毫秒时间计算时,千万要注意int和long的使用,看下例,小心别踩了雷。
/**
* java时间计算(int和long要注意,一定要选择long)
* @author 崔卫兵
*
*/
public class TimeTester {
/**
* 计算几天前的毫秒数
& ......
对于这个系列里的问题,每个学Java的人都应该搞懂。当然,如果只是学Java玩玩就无所谓了。如果你认为自己已经超越初学者了,却不很懂这些问题,请将你自己重归初学者行列。内容均来自于CSDN的经典老贴。
问题一:我声明了什么!
String s = "Hello world!";
许多人都做过这样的事情,但是,我们到底声明了什么? ......
算术异常类:ArithmeticExecption
空指针异常类:NullPointerException
类型强制转换异常:ClassCastException
数组负下标异常:NegativeArrayException
数组下标越界异常:ArrayIndexOutOfBoundsException
违背安全原则异常:SecturityException
文件已结束异常:EOFException
文件未找到异常:FileNotFound ......
class Link
{
private Node head;
public Link(Node head)
{
this.head=head;
}
public void addNode(Node node)
{
Node p=head;
while(true)
{
if(!p.hasNext())
{
p.setNext(node);
break;
}
p=p.getNext();
}
}
//插入节
public void insertNode(Node p,Node q)
{
q.setNext(p.getNext());
p.se ......