Savitch Absolute Java Third Edition.
By Addison Wesley.
Source Code of any chapter of book.
Chapter1.GETTING STARTED
FirstProgram.javapublic class FirstProgram
{
public static void main(String[] args)
{
System.out.println("Hello reader.");
System.out.println("Welcome to Java.");
System.out.println("Let's demonstrate a simple calculation.");
int answer;
answer = 2 + 2;
System.out.println("2 plus 2 is " + answer);
}
}
ShowInterest.java/**
Program to show interest on a sample account balance.
Author: Jane Q. Programmer.
E-mail Address: janeq@somemachine.etc.etc.
Last Changed: September 21, 2004.
*/
public class ShowInterest
{
public static final double INTEREST_RATE = 2.5;
public static void main(String[] args)
{
double balance = 100;
double interest; //as a percent
interest = balance * (INTEREST_RATE/100.0);
System.out.println("On a balance of $" + balance);
System.out.println("you will earn interest of $"
+ interest);
System.out.println("All in just one short year.");
}
}
StringProcessingDemo.javapublic class StringProcessingDemo
{
public static void main(String[] args)
{
String sentence = "I hate text processing!";
int position = sentence.indexOf("hate");
String ending =
sentence.substring(position + "hate".length( ));
System.out.println("01234567890123456789012");
System.out.println(sentence);
System.out.println("The word \"hate\" starts at index "
+ position);
sentence = sentence.substring(0, position) + "adore"
+ ending;
System.out.println("The changed string is:");
System.out.println(sentence);
}
}
導覽連結: 首頁 -> 標題: Chapter1.GETTING STARTED
2007年10月11日 星期四
Chapter1.GETTING STARTED
ARTICLE LABELS: Source Code
訂閱:
張貼留言 (Atom)
0 COMMENT:
張貼留言