Java作业@笔试题@2017.11.04-11.05
来源:互联网 发布:怎么开店淘宝店 编辑:程序博客网 时间:2024/06/08 19:11
1:需求:请设计一个方法,可以实现获取任意范围内的随机数。
package org.wests.InterviewQuestion;/** * 1:需求:请设计一个方法,可以实现获取任意范围内的随机数。 * @author 代虎 * */public class Question01 { public static void getRandom(double start,double end) { double random = Math.random()*(end-start)+start; System.out.println(random); } public static void main(String[] args) { getRandom(10, 20); getRandom(0, 20); getRandom(100, 200); }}
执行结果:
15.760649486959991
12.00285416285148
145.76020942009
2:下面代码执行的结果是:public static void main(String[] args) { String s1 = new String("hello"); String s2 = new String("hello"); System.out.print(s1 == s2); System.out.print(","); System.out.println(s1.equals(s2)); }}
执行结果:false,true
3:下面代码执行的结果是:
public static void main(String arg[]) { StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operate(a, b); System.out.println(a + "," + b); } static void operate(StringBuffer x, StringBuffer y) { x.append(y); y = x; }
执行结果:AB,B
4、下列代码的执行结果是:
String str1 = "This is a test!"; StringBuffer str2 =new StringBuffer( "This is a test!"); str1 = str1+"Hi"; str2.append("Hi"); System.out.println("str1 == " + str1); System.out.println("str2 == " + str2);
执行结果:str1 == This is a test ! Hi
str2 == This is a test ! Hi
以下为反编译的结果:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.// Jad home page: http://kpdus.tripod.com/jad.html// Decompiler options: packimports(3) fieldsfirst ansi space // Source File Name: Question04.javapackage org.wests.InterviewQuestion;import java.io.PrintStream;public class Question04{ public Question04() { } public static void main(String args[]) { String str1 = "This is a test!"; StringBuffer str2 = new StringBuffer("This is a test!"); str1 = (new StringBuilder(String.valueOf(str1))).append("Hi").toString(); str2.append("Hi"); System.out.println((new StringBuilder("str1 == ")).append(str1).toString()); System.out.println((new StringBuilder("str2 == ")).append(str2).toString()); }}
5:下面代码能最后打印的值是?
public class TestValue { private static int a; public static void main(String[] args) { modify(a); System.out.println(a); } public static void modify(int a) { a++; }
执行结果: 0
阅读全文
1 0
- Java作业@笔试题@2017.11.04-11.05
- Java作业@2017.11.04-11.05
- 【Java作业】2017.11.04 / 11.05
- 华为Java笔试题笔试
- 作业帮的笔试
- java作业第一题
- java笔试题
- java笔试题
- Java笔试题
- java经典笔试题
- 一JAVA笔试题
- Java笔试题集锦
- JAVA笔试题
- java笔试题大全
- 一道java笔试题
- JAVA笔试题
- Java笔试题
- Java笔试题总结
- 高性能 javaScript 之遍历对象属性
- testng源码阅读之6
- 工厂模式
- JS DOM(一)
- Linux自带JDK安装目录查询
- Java作业@笔试题@2017.11.04-11.05
- 资源视频学习JavaSE阶段整理笔记
- Cake ZOJ
- 【OpenCV】图像金字塔
- cmd 命令提示符
- 1571.八数码
- 【cs231n】assignment1 :Multiclass Support Vector Machine exercise
- 第一章:图像处理与分析导论
- 代码检视工具Gerrit的日常使用