30天代码day1Data Types
Primitive Data Types
Java has 8 primitive data types: byte, short, int, long, float, double, boolean, and char. For most challenges, you'll only need to concern yourselves with ints (e.g.: 1, 2, 3, etc.) and doubles (e.g.: 1.0, 2.5, 3.9, etc.). Another important data type we mentioned yesterday is the String class, whose objects are immutable(不可变) strings of characters.
Scanner
Yesterday, we discussed Scanner's next, nextLine, hasNext, and hasNextLine methods. Scanner also has readNext and hasNext methods for different data types, which is very helpful when you know exactly what type of input you'll be reading. The next methods scan for tokens (you can think of this as a word), and the nextLine methods reads from the Scanner's current location until the beginning of the next line. For example, nextInt() will scan the next token of input as an int, and nextDouble() will scan the next token of input as a double. You should only ever use 1 scanner object for your entire program.
Each line of multi-line input contains an invisible separator indicating that the end of a line of input has been reached. When you use Scanner functions that read tokens (e.g.: next(), nextInt(), etc.), the Scanner reads and returns the next token. When you read an entire line (i.e.: readLine()), it reads from the current position until the beginning of the next line. Because of this, a call to nextLine() may return an empty string if there are no characters between the end of the last read and the beginning of the next line. For example, given the following input:
a b c
d e
f
g
The breakdown below shows how a certain sequence of calls to a Scanner object, , will read the above input:
- A call to
scan.next();returns the next token,a. - A call to
scan.next();returns the next token,b. - A call to
scan.nextLine();returns the next token,c. It's important to note that the scanner returns a space and a letter, because it's reading from the end of the last token until the beginning of the next line. - A call to
scan.nextLine();returns the contents of the next line,d e. - A call to
scan.next();returns the next token,f. - A call to
scan.nextLine();returns everything afterfuntil the beginning of the next line; because there are no characters there, it returns an empty String. - A call to
scan.nextLine();returnsg.
Note: a token (single word)
Additive Operator
The + operator is used for mathematical addition and String concatenation (i.e.: combining two Strings into one new String). If you add the contents of two variables together (e.g.: a + b), you can assign their result to another variable using the assignment operator (=). You can also pass the result to a function instead of assigning it to a variable; for example, if a = 1 and b = 2, System.out.println(a + b); will print 3 on a new line.
30天代码day1Data Types的更多相关文章
- 30行代码搞定WCF并发性能测试
[以下只是个人观点,欢迎交流] 30行代码搞定WCF并发性能 轻量级测试. 1. 调用并发测试接口 static void Main() { List< ...
- 30行代码让你理解angular依赖注入:angular 依赖注入原理
依赖注入(Dependency Injection,简称DI)是像C#,java等典型的面向对象语言框架设计原则控制反转的一种典型的一种实现方式,angular把它引入到js中,介绍angular依赖 ...
- 30行代码实现Javascript中的MVC
从09年左右开始,MVC逐渐在前端领域大放异彩,并终于在刚刚过去的2015年随着React Native的推出而迎来大爆发:AngularJS.EmberJS.Backbone.ReactJS.Rio ...
- Tensorflow快餐教程(1) - 30行代码搞定手写识别
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/lusing/article/details ...
- 10分钟教你用python 30行代码搞定简单手写识别!
欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 手写笔记还是电子笔记好呢? 毕业季刚结束,眼瞅着2018级小萌新马上就要来了,老腊肉小编为了咱学弟学妹们的学习,绞尽脑汁准备编一套大学秘籍, ...
- JAVA_SE基础——30.构造代码块
黑马程序员入学blog...构造代码块作用:给所有的对象进行统一的初始化. 问题:要求每个小孩出生都会哭,这份代码有两个构造函数,如果需要每个小孩出生都要哭的话,那么就需要在不同的构造函数中都调用cr ...
- 30天代码day4 Class vs. Instance
Class A blueprint defining the charactaristics and behaviors of an object of that class type. Class ...
- 30天代码day2 Operators
Operators These allow you to perform certain operations on your data. There are 3 basic types: Unary ...
- 30 行代码实现 JS 中的 MVC
一连串的名字走马观花式的出现和更迭,它们中一些已经渐渐淡出了大家的视野,一些还在迅速茁壮成长,一些则已经在特定的生态环境中独当一面舍我其谁.但不论如何,MVC已经并将持续深刻地影响前端工程师们的思维方 ...
随机推荐
- MATLAB中a(:)和." ' "," ' "
今天继续学习matlab看书时发现了一行代码 a=a(:).'; 起初可能不懂就百度一下 a(:)可以将向量转换为列向量,行向量相当于直接转置,列向量不变 而如果是n*m维向量则仍然是以列为主,即按照 ...
- js的回调函数
介绍首先从英文介绍开始 A callback is a function that is passed as an argument to another function and is execut ...
- 从SQLServer转储数据到MySQL
前一段时间,由于项目需要将数据库从SQLServer迁移到MySQL,在网上百度了很久,基本都是通过SQLyog实现的.其实使用平时常用的数据库管理软件Navicat Premium也能做到,并且操作 ...
- Python——字符串、文件操作,英文词频统计预处理
一.字符串操作: 解析身份证号:生日.性别.出生地等. 凯撒密码编码与解码 网址观察与批量生成 2.凯撒密码编码与解码 凯撒加密法的替换方法是通过排列明文和密文字母表,密文字母表示通过将明文字母表向左 ...
- spring cloud 服务A调用服务B自定义token消失,记录
后端:spring cloud 前端:vue 场景:前端ajax请求,包装自定义请求头token到后台做验证,首先调用A服务,A服务通过Feign调用B服务发现自定义token没有传到B服务去; 原因 ...
- 实现对HashMap的value排序
问题:如何对HashMap中的value值进行排序 关键点:1.取HashMap的Map.Entry,放入List2.利用Collections.sort(List, Comparator<? ...
- 通用c程序Makefile
#一个通用的Makefile,可以在linux各大平台下通用编译c程序,这个版本在gcc平台下实现,如需要课更改第二部的gcc,也可以在第三部添加所需要的库,如有错误,欢迎即使纠正 #1.遵循可移植操 ...
- 一些不常用的Oracle用法记录(含模糊查询)
(一).判断 某字段 是否包含 某字符串 select * from mc_member m where instr(m.bu, 'BU') > 0 --查询bu包含'BU' (二).将 某字段 ...
- bootstrap-fileinput多图片上传
在页面写一个input框: <input id="subGraphAddress1" name="subGraphAddress" type=" ...
- Java中的静态方法和实例方法的调用的理解(不同的类下的方法调用)
public class MethodCall { public static void main(String[] args) { Test.sayStatic(); Test test = new ...