2017.11.4
来源:互联网 发布:看门狗pc优化补丁 编辑:程序博客网 时间:2024/06/05 07:18
1:需求:请设计一个方法,可以实现获取任意范围内的随机数。
package aa;import java.util.Random;import java.util.Scanner;/** * * @author naughtymonkey * */public class Test1 { public static void main(String[] args) { System.out.println("请输入取值的范围:max min"); Scanner scan=new Scanner(System.in); int max=scan.nextInt(); int min=scan.nextInt(); int random=random(max,min); System.out.println(random); } /** * * @param max 随机数的最大取值 * @param min 随机数的最小取值 * @return 范围内的随机数 */ public static int random(int max,int min){ if(max<=min){ return -1; }else{ return new Random().nextInt(max)%(max-min+1)+min; } }}
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
6、下列代码的执行结果是:
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
7:下面代码能最后打印的值是?
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++; }}A)编译错误 B)null C)0 D)1选 C
阅读全文
0 0
- 2017.11.4
- 2017.11.4
- 2017.11.4 新工作
- 2017.11.4总结
- 2017.11.4 LeetCode
- 2017.11.4 (c)
- 2017.11.01
- 2017.11.1
- 2017.11.2
- 2017.11.02
- 2017.11.3
- 2017.11.3
- 2017.11.5
- 2017.11.03
- 2017.11.5
- 2017.11.5
- 2017.11.6
- 2017.11.06
- Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.a
- 【Mysql】主从配置,实现读写分离
- python3.6 源码分析(五):类的创建
- 很简单的git和GitHub入门
- 【BZOJ2208】【JSOI2010】连通数 传递闭包
- 2017.11.4
- Android开发禁止返回键与禁止返回上一次
- 并查集
- 算术运算的应用
- Oracle存储过程实例集锦
- HDU4349-Xiao Ming's Hope(Lucas定理)
- Ubuntu14.04下Qt5+opencv3.0安装和配置
- Ubuntu环境配置之显卡驱动安装、vim
- Hadoop之HDFS复习