课程: Java for All Platforms: Desktop, Web, and Mobile Development
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Conditional statements - Java教程
课程: Java for All Platforms: Desktop, Web, and Mobile Development
Conditional statements
- [Instructor] Conditional statements allow you to run a block of code if a certain condition is met. Let's take a look at how that works. As an example, let's create an Integer variable. We'll just call it myInteger and we'll set it equal to null. Remember as we've talked about earlier, this particular data type, Integer with a capital I, allows null values. So let's say we're trying to print the value of this. System.out.println. myInteger.toString. So we're taking the integer, converting it to a string and printing it out. Watch what happens when we try to run the application. We get this NullPointerException because we're trying to run a method on an object that is set to null. So one way to handle this is to use conditional statements. Underneath the variable declaration line, type the keyword if to create a conditional statement and in parentheses, myInteger not equals null. So we're only going to run…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
(已锁定)
Variables4 分钟 4 秒
-
(已锁定)
Functions4 分钟 40 秒
-
(已锁定)
Arrays and lists6 分钟 17 秒
-
(已锁定)
Conditional statements3 分钟 45 秒
-
(已锁定)
Classes and packages6 分钟 14 秒
-
(已锁定)
Input and output2 分钟 26 秒
-
(已锁定)
Read data from a file4 分钟 12 秒
-
(已锁定)
Handle Java errors3 分钟 26 秒
-
(已锁定)
Challenge: Sum of a list54 秒
-
(已锁定)
-
-
-
-
-