《JAVA语言程序设计与数据结构》(基础篇)原书第11版 第一章(答案)

《JAVA语言程序设计与数据结构》(基础篇)原书第11版

第一章(答案)

1.1
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
public class book1_5{
   
    public static void main(String[] args){
   
        
        double result = (9.5 * 4.5 - 2.5 * 3.0) / (45.5 - 3.5);
        System.out.println(result)
  • 9
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值