首页 > 编程知识 正文

java语言程序设计第二版答案,java程序设计教程第三版课后答案

时间:2023-05-05 16:22:02 阅读:178750 作者:1044

专业整理

知识共享

习题

2

3

.“

=

=

”比较相同内容的字符串

比较一下,看看会产生什么样的结果。

答:首先,有两种方法可以创建字符串变量。

stringstr=newstring(ABC );

Stringstr='abc '

" "

==

”是因为制作的形式不同而发生的

不同的结果:

Stringstr1='abc ';

Stringstr2='abc ';

system.out.println(str1=

=str2;

//true

stringstr1=newstring(ABC );

Stringstr2='abc ';

system.out.println(str1=

=str2;

//false

stringstr1=newstring(ABC );

stringstr2=newstring(ABC );

system.out.println(str1=

=str2;

//false

因此,在比较内容时,使用自符号串

equals

方法比较可靠。

Stringstr1='abc ';

Stringstr2='abc ';

system.out.println(str1=

=str2;

//true

stringstr1=newstring(ABC );

Stringstr2='abc ';

system.out.println(str1.equals ) str2);

//true

stringstr1=newstring(ABC );

stringstr2=newstring(ABC );

system.out.println(str1.equals ) str2);

//true

5

.变量为

n

的初始值设定

,来定义您自己的自订外观

1678

然后利用除法和剩余运算来改变

的各数字并打印,然后输出结果

如下所示。

n=1678。

n

的各个数字是

1

6

7

8。

如果

n

是任意值吗?

法一:

公共类执行5 {

公共

静态

void

main(string[]

args ()。

intn=1678;

intunit;

intdecimal;

inthundred;

intthousand;

intcount;

thousand=n/1000;

count=n00;

hundred=count/100;

count=count0;

decimal=count/10;

计数=计数器;

单元=计数;

system.out.println('1678

包含的数量

各个字如下。

' thousand ',' hundred ',' decimal ',

' unit;

}

}

//

如果

n

任意值

importjava.io.*;

公共类执行51 {

公共

静态

void

main(string[]

args )

throwsIOException{

System.out.print (

请讲

会输的

管教

数量:

();

InputStreamReaderisStream=new

输入流读取器(system.in;

BufferedReaderbfReader=new

缓冲读我(is stream;

斯汀

input=bfReader.readLine (;

intlength=input.length((-1;

intn=new

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。