public class book1_1{
public static void main (String[] args){
System.out.print("Welcome to Java."); // print 不换行。
System.out.println("Welcome to Science."); // println 换行。
System.out.printf("Programming is fun."); // printf 类似与c语言中printf函数。
}
}
1.2
public class book1_2{
public static void main (String[] args){
for (int i = 0; i < 5; i ++) // 计数技巧
System.out.println("Welcome to Java !");
}
}
1.3
public class book1_3 {
public static void main(String[] args){
System.out.printf(" J A V V A %n" + // '+' 字符串的拼接
" J A A V V A A %n" + // %n 换行
"J J AAAAA V V AAAAA %n" +
" JJ A A V A A %n" );
}
}
1.4
public class book1_4{
public static void main(String[] args){
String head1="a"; // 创建 string 类型的数据 s
String head2="a^2";
String head3="a^3";
System.out.printf("%-7s%-7s%-7s%n",head1,head2,head3);
/* %-7s 从左往右占七个字符,不足右边空格补齐。
%s 对应字符串。
%d 对应整数。 */
for(int i=1;i<5;i++)
System.out.printf("%-7d%-7d%-7d%n",i,i*i,i*i*i);
}
}
1.5
publicclassbook1_5{
publicstaticvoidmain(String[] args){
double result =(9.5*4.5-2.5*3.0)/(45.5-3.5);
System.out.println(result)
《JAVA语言程序设计与数据结构》(基础篇)原书第11版第一章(答案)1.1public class book1_1{ public static void main (String[] args){ System.out.print("Welcome to Java."); // print 不换行。 System.out.println("Welcome to Science."); // println 换行。 Syste