- 博客(20)
- 收藏
- 关注
原创 Java练习002 - 从控制台接收输入的身份证号码
从控制台接收输入的身份证号码-Java练习002System类包含in(输入流),out,err(输出流)等成员,in用来接收用户的输入。**关键技术:**System.in 输入流搭配Scanner扫描类的用法和Scanner对象方法nextLine()的用法 //从控制台接收输入的身份证号码 /* System类包含in(输入流),out,err(输出流)等成员,in...
2019-08-08 21:57:37
1164
原创 Java练习001 - 判断是否是闰年
判断是否是闰年##判断某一年是否为闰年leap year满足闰年的条件:非整百年份可被4整除,可被400整除,被100整除的不是闰年package com.benjamin.chapter01;import java.util.Scanner;public class Demo001 { public static void main(String[] agrs){...
2019-08-08 18:24:07
302
原创 C++Primer(第5版) Exercises Section 2.2.1
Exercise 2.9: Explain the following definitions. For those that are illegal, explain what’s wrong and how to correct it. (a) std::cin >> int input_value; (b) int i = { 3.14 }; (c) doub...
2018-02-26 20:48:44
355
原创 C++Primer(5th) Exercises Section 2.1.3
Exercise 2.5: Determine the type of each of the following literals. Explain the differences among the literals in each of the four examples: (a) ‘a’, L’a’, “a”, L”a” (b) 10, 10u, 10L, 10uL, 012...
2018-02-26 16:58:33
440
原创 C++Primer(第5版)2.1.2节练习
2.1.2节练习 练习2.3:读程序写结果singed u = 10, u2 = 42;std::cout << u2-u << std::endl;std::cout << u –u2 <<std::endl;int i = 10, i2 = 42;std::cout << i2 – i <<std::en...
2018-02-26 12:32:23
303
原创 C++Primer(第5版)2.1.1节练习
练习2.1:类型int,long,long long和short的区别是什么?无符号类型和带符号类型的区别是什么?float和double的区别是什么?Answer:类型int,long,long long和short的区别是什么?int类型最小尺寸是16位long类型最小尺寸是32位long long类型最小尺寸是64位short类型最小尺寸是16位无符号类型和带符号类型的区别是什么?无符号类型...
2018-02-26 11:54:27
560
原创 C++Primer(第5版) 1.6节练习
练习1.25 借助网站上的Sales_item.h 头文件,编译并运行本节给出的书店程序#include <iostream>#include "Sales_item.h"int main() { Sales_item total; if(std::cin>>total) { Sales_item trans; w...
2018-02-25 21:32:20
336
原创 C++Primer(第5版) 1.5.2节练习
练习1.23:编写程序,读取多条销售记录,并统计每个ISBN有几条销售记录。#include <iostream>#include "Sales_item.h"int main() { Sales_item item; Sales_item curItem; if(std::cin>>curItem) { int cnt=...
2018-02-25 21:14:19
668
3
原创 C++Primer(第5版) 1.5.1节练习
练习 1.20: 编写一个程序,读取一组书籍销售记录,将每条记录打印到标准输出上#include <iostream>#include "Sales_item.h"int main() { Sales_item book; std::cin>>book; std::cout<<book<<std::endl; re...
2018-02-25 20:27:09
583
原创 C++Primer(第5版) 1.4.4节练习
练习1.17:如果输入的所有值都是相等的,本节的程序会输出什么?如果没有重复值,输出又会是怎么样的?#include <iostream>int main() { int currVal = 0, val = 0; if(std::cin>>currVal){ int cnt = 1; while (std::cin>...
2018-02-25 19:05:37
488
原创 C++Primer(第5版) 1.4.3节练习
练习1.16: 编写程序,从cin读取一组数,输出其和。#include <iostream>int main() { int value; int sum = 0; std::cout<<"Enter some integers and end with any char key\n"; while(std::cin>>v...
2018-02-25 18:15:34
374
原创 C++Primer(第5版) 1.4.2节练习
练习 1.12: 下面的for循环完成了什么功能?sum的终值是多少?#include <iostream>int main() { int sum = 0; for (int i = -100; i <= 100; ++i) { sum += i; } std::cout<<"Sum: "<<sum&...
2018-02-25 18:00:33
266
原创 C++Primer(第5版) 1.4.1节练习
练习1.9:编写程序,使用while循环将50到100的整数相加#include <iostream>using namespace std;int main() { int sum = 0; int i = 50; while(i<=100) { sum+=i; i++; }; cout ...
2018-02-25 16:50:46
507
原创 C++Primer(第5版) 1.3节练习
练习 1.7: 编译一个包含不正确的嵌套注视的程序,观察编译器返回的错误信息。例如:#include <iostream>int main() { std::cout << "Hello, World!" << std::endl; /* * This is a comment /* * This is ano...
2018-02-25 14:27:21
529
原创 练习1.6 解释下面程序片段是否合法
解释下面程序片段是否合法。 std::cout << "The sum of " << v1; //合法 <<" and " << v2; //不合法,开头缺少 std::cout <<" is " << v1 + v1 &
2018-02-25 14:02:01
775
原创 练习1.5 重写程序,将每个运算对象的打印操作放在一条独立的语句中
//我们将所有输出操作放在一条很长的语句中。//重写程序,将每个运算对象的打印操作放在一条独立的语句中#include <iostream>using namespace std;int main() { int a = 100,b = 25; cout << a; cout << " * "; cout <<...
2018-02-25 13:47:10
388
原创 练习1.4 编写程序使用乘法运算符*,来打印两个数的积
//我们的程序使用加法运算符+来将两个数相加。//编写程序使用乘法运算符*,来打印两个数的积。#include <iostream>using namespace std;int main() { int num1=3,num2=6; cout << "num1 * num2 = " << num1*num2 <<endl;...
2018-02-25 13:37:42
1161
原创 练习1.3 编写程序,在标准输出上打印Hello,World!
//编写程序,在标准输出上打印Hello,World。#include <iostream>int main() { std::cout << "Hello, World!" << std::endl; return 0;}输出结果/Users/benjaminliu/C++Primer/1.3/cmake-build-debug/1_...
2018-02-25 13:25:27
7352
原创 练习1.2 改写程序,让它返回-1
改写程序,让它返回-1。返回值-1通常被当作程序错误的标识。重新编译并运行你的程序,观察你的系统如何处理main返回的错误标识。#include <iostream>int main() { return -1;}输出结果:/Users/benjaminliu/C++Primer/1.2/cmake-build-debug/1_2Process finished ...
2018-02-25 13:01:55
797
原创 练习1.1 编译并运行第2页的main程序
练习1.1:查阅你使用的编译器的文档,确定它使用的文件命名约定。 编译并运行第2页的main程序#include <iostream>int main() { return 0;}
2018-02-25 11:27:43
234
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人