Chapter 4 : Control Structures 1 : Selection

Although it need not be, the expression is usually an identifier. Whether it is an identifier
or an expression, the value of the identifier or the expression can only be of type int, byte, short,
or char.

public class StringComapre {

    public static void main(String[] args) {    

    String    str1 = new String("Hello");
    String    str2 = "Hello";

    if (str1 == str2)
        System.out.println("str1 equal str2");
    else
        System.out.println("str1 != str2");

    ////////////////////////////////////////////////////////

    String    str3 = "Hello";
    String    str4 = new String("Hello");

    if (str3 == str4)
        System.out.println("str3 equal str4");
    else
        System.out.println("str3 != str4");

    ///////////////////////////////////////////////////////

    String    str5 = new String("Hello");
    String    str6 = new String("Hello");

    if (str5 == str6)
        System.out.println("str5 equal str6");
    else
        System.out.println("str5 != str6");

    }
}

这段代码有疑问,为什么str1 和 str2不相等?

时间: 2024-11-05 06:14:15

Chapter 4 : Control Structures 1 : Selection的相关文章

Chapter 5 : Control Structures 2 : Repetition

1 import java.util.*; 2 import java.io.*; 3 4 public class Loop { 5 6 static Scanner console = new Scanner(System.in); 7 8 public static void main(String[] args) { 9 10 int i = 0; 11 int sum = 0; 12 13 while ( console.hasNext() ) { 14 i = console.nex

Scala Control Structures

Scala之Control Structures 一.前言 前面学习了Scala的Numbers,接着学习Scala的Control Structures(控制结构). 二.Control Structures Scala中的控制结构与Java中的颇为类似,但也有所不同,例如,if/then/else控制结构与Java的类似,但是其可以返回值,虽然Java中有三元运算符的特殊语法,但是在Scala中使用if就可以达到同样的效果. val x = if (a) y else z 同样,Scala的

CCJ PRML Study Note - Chapter 1.3-1.4 : Model Selection & the Curse of Dimensionality

Chapter 1.3-1.4 : Model Selection & the Curse of Dimensionality Chapter 1.3-1.4 : Model Selection & the Curse of Dimensionality Christopher M. Bishop, PRML, Chapter 1 Introdcution 1. Model Selection In our example of polynomial curve fitting using

【Scala】Scala之Control Structures

一.前言 前面学习了Scala的Numbers,接着学习Scala的Control Structures(控制结构). 二.Control Structures Scala中的控制结构与Java中的颇为类似,但也有所不同,例如,if/then/else控制结构与Java的类似,但是其可以返回值,虽然Java中有三元运算符的特殊语法,但是在Scala中使用if就可以达到同样的效果. val x = if (a) y else z 同样,Scala的try/catch/finally 结构与Java

R Programming week2 Control Structures

Control Structures Control structures in R allow you to control the flow of execution of the program, depending on runtime conditions. Common structures are: if, else: testing a condition for: execute a loop a fixed number of times while: execute a l

Methods and systems to control virtual machines

Methods and systems are provided to control the execution of a virtual machine (VM). A VM Monitor (VMM) accesses VM Control Structures (VMCS) indirectly through access instructions passed to a processor. In one embodiment, the access instructions inc

A GUIDE TO UNDERSTANDINGDISCRETIONARY ACCESS CONTROL INTRUSTED SYSTEMS

1. INTRODUCTION ? The main goal of the National Computer Security Center is to encourage the widespread availability of trusted computer systems. In support of that goal a metric was created, the Department of Defense Trusted Computer System Evaluati

listview control messages

CTreeCtrl是在OnNMCustomdraw中自绘的,不要设定其他属性 CListCtrl是在DrawItem中自绘的,要设定属性LVS_OWNERDRAWFIXED|LVS_REPORT CButton是在DrawItem中自绘的,要设定属性BS_OWNERDRAW CMenu是在DrawItem中自绘的,要把每一项都设定属性MF_OWNERDRAW,用到递归方法 单选按钮是基于CButton在DrawItem中自绘的,要重写Create设定属性为 dwStyle &= ~(0xF);

MFC Grid control 2.27

MFC Grid control author:songyanwu MFC Grid control属性介绍: The control features: Cell selection using the mouse, with optional Control and Shift key combinations. Selection can be disabled. Row and Column resizing. Sizing can be disabled for row, column