Java题整】的更多相关文章

Java面试题整 http://www.cnblogs.com/remember-forget/p/6140166.html 上:http://blog.csdn.net/jackfrued/article/details/44921941 中:http://blog.csdn.net/jackfrued/article/details/44931137 下:http://blog.csdn.net/jackfrued/article/details/44931161…
JAVA取整以及四舍五入 import java.math.BigDecimal; //引入这个包 public class Test { public static void main(String[] args) { double i = 3.856; // 舍掉小数取整 System.out.println("舍掉小数取整:Math.floor(3.856)=" + (int) Math.floor(i)); // 四舍五入取整 System.out.println("…
JAVA 长整型转换为IP地址的方法 代码例如以下: /** * 整型解析为IP地址 * @param num * @return */ public static String int2iP(Long num) { String str = null; Long[] tt = new Long[4]; tt[0] = (num >>> 24) >>> 0; tt[1] = ((num << 8) >>> 24) >>>…
JAVA的整型与字符串相互转换1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或         i = Integer.parseInt([String],[int radix]); 2). int i = Integer.valueOf(my_str).intValue(); 注: 字串转成 Double, Float, Long 的方法大同小异. 2 如何将整数 int 转换成字串 Str…
问题 为什么在重写equals()方法的同时,必须重写hashCode()方法? 解答 在<每天一道Java题[2]>中,已经对hashCode()能否判断两个对象是否相等做出了解释.equals()方法与hashCode()方法的关系如下: 如果两个对象的hashCode()返回值不一样,则equals()返回的结果必为false. 如果两个对象的hashCode()返回值一样的时候,equals()返回的结果未知. 如果两个对象的equals()返回的结果为true,则两个对象的hashC…
题目 synchronized怎么实现线程同步?请修改<每天一道Java题[10]>中的MyRunnableThread类以解决三个线程都获取到10的问题. 解答 方法一: 采用synchronized关键字包裹需要保证线程安全的代码块,来实现线程同步.语法格式为: Synchronized(expression){ //需同步的代码 } <每天一道Java题[10]>中的MyRunnableThread类修改为: package me.huangzijian; public cl…
java取整和java四舍五入方法 import java.math.BigDecimal; import java.text.DecimalFormat; public class TestGetInt{ public static void main(String[] args){    double i=2, j=2.1, k=2.5, m=2.9;    System.out.println("舍掉小数取整:Math.floor(2)=" + (int)Math.floor(i…
先看下这段神奇的Java代码: public static void main(String[] args) throws Exception { doSomethingMagic(); System.out.printf("2 + 2 = %d", 2 + 2); } 执行结果:2 + 2 = 5 那么doSomethingMagic到底做了什么神奇的事情呢?先看代码: private static void doSomethingMagic() throws Exception {…
Java中整数值有4中表示方式:十进制.二进制.八进制和十六进制,其中二进制的整数以0b或0B开头:八进制的整数以0开头: 十六进制的整数以0x或0X开头,其中10-15分别以a-f(此处的a-f不区分大小写)来表示. 1.八进制表示整数值. int octalValue = 013; System.out.println("八进制的整数打印后为:"+octalValue); 2.十六进制表示整数值. int hexValue1 = 0x13; System.out.println(&…
import java.math.BigDecimal; public class TestGetInt { public static void main(String[] args) { double i = 2, j = 2.1, k = 2.5, m = 2.9; System.out.println("舍掉小数取整:Math.floor(2)=" + ( System.out.println("舍掉小数取整:Math.floor(2.1)=" + ( Sy…
import java.math.BigDecimal; import java.text.DecimalFormat; public class TestGetInt{ public static void main(String[] args){    double i=2, j=2.1, k=2.5, m=2.9;    System.out.println("舍掉小数取整:Math.floor(2)=" + (int)Math.floor(i));    System.out.…
[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析:   兔子的规律为数列1,1,2,3,5,8,13,21.... [程序2] 题目:判断101-200之间有多少个素数,并输出所有素数. 1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数. [程序3] 题目:打印出所有的 "水仙花数 ",所谓 &…
转载自:http://www.cnblogs.com/heshan664754022/archive/2013/03/24/2979495.html 十年半山 今天在论坛闲逛的时候发现了一个很有趣的题目: package test; public class Test { public void myMethod(String str) { System.err.println("string"); } public void myMethod(Object obj) { System…
1.下面中哪两个可以在A的子类中使用:( ) class A { protected int method1 (int a, int b) { return 0; } } A. public int method 1 (int a, int b) { return 0; } B. private int method1 (int a, int b) { return 0; } C. private int method1 (int a, long b) { return 0; } D. publ…
前言 不论你是职场新人还是步入职场N年的职场新人大哥大~当然这个N<3~,我能担保你答不对这十个题~不要问我为什么这么自信~,这些个题还是"有水平"的javase的基础题,传闻小白指定鸭蛋分,一测一个准,哈哈. 作为将来要成为架构师的男人,对,你没看错,就是在说你 ~皮一下很开森~ ,what?你是小白?我顶你个肺,我叫声杠精,你敢应吗,那个代号9527的杠精,说你呢快快来答题,看你能答对几道题. 题一 下面的程序有问题吗?如果有问题说明一下, 如果没有问题猜测一下运行结果 pu…
最近在修改公司之前的项目,在项目中遇到了权限校验的问题,代码中出现了BigInteger的setBit()testBit()方法,之前未接触过,所以了解了下BigInteger. 在Java中,由CPU原生提供的整型最大范围是64位long型整数.使用long型整数可以直接通过CPU指令进行计算,速度非常快. 如果我们使用的整数范围超过了long型怎么办?这个时候,就只能用软件来模拟一个大整数.java.math.BigInteger就是用来表示任意大小的整数.BigInteger内部用一个in…
)What is the output of running class Test? public class Test { public static void main(String[ ] args) { new Circle9(); } } public abstract class GeometricObject { protected GeometricObject() { System.out.print("A"); } protected GeometricObject(…
1)________ represents an entity(实体) in the real world that can be distinctly identified. 1) _______ A)A data field B) An object C)A method D) A class 2)________ is a construct that defines objects of the same type.  2) _______ A)A method B) A data fi…
1)Suppose your method does not return any value, which of the following keywords can be used as a return type? A)void  B)public  C)int  D)double  E)None of the above 2)The signature(函数签名) of a method consists of ________.  A)method name and parameter…
1)Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read an int value? A) input.nextInteger(); B) input.integer(); C) input.nextInt(); D) input.int(); 2)The following code fragment reads…
package cn.bdqn.com; import java.util.Scanner; public class Jisaunqi { int num1; int num2; int jieguo; public void show(){ Scanner input=new Scanner(System.in); String fuhao1=input.next(); char fuhao2=fuhao1.charAt(0); switch(fuhao2){ case '+': jiegu…
1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String],[int radix]); 2). int i = Integer.valueOf(my_str).intValue(); 注: 字串转成 Double, Float, Long 的方法大同小异. 2 如何将整数 int 转换成字串 String ? A. 有叁种方法: 1.) Str…
这是一个源自知乎的话题,原贴链接:一道百度的面试题,有大神会嘛? 虽然我不是大神,但我也点进去看了一下,思考了一会之后有了一些思路,然后去看其它人的答案的时候果然全都已经被各路大神们先想到并贴出来了,所以我就不去凑热闹写重复答案了,整理一下网友们的智慧在这里自娱自乐好了. 题目 思路一 作为一个多年前也见过不少笔试题的少年,看到这个题目的第一想法是脑筋急转弯——注入一段逻辑直接改变原 if 结构. 解法一 填入内容 true){System.out.print("a");}if(fal…
向上取整用Math.ceil(double a) 向下取整用Math.floor(double a) 举例: public static void main(String[] args) throws Exception { double a = 35; double b = 20; double c = a / b; System.out.println("c===>" + c); // 1.75 System.out.println("c===>"…
问题 怎么将字符串转换为int? 解答 此题看似简单,但经常出现在笔试等地方,由于大家习惯了用IDE,有什么还真未必能写出来.通常都是parseInt()方法进行转换,如下: Int n = Integer.parseInt("123"); 发散思考 1.除了parseInt()方法外,还有什么其它方法可以让String转换为int吗?float.double.long.short那些又是怎么从String转换的? 解答:除了parseInt()方法以外,还可以用valueOf()方法…
题目 String字符串怎么转换为Date,Date又怎么转换成String字符串 解答 String->Date 主要用到类SimpleDateFormat及其抽象父类DateFormat中的方法parse(). 如下: String dateStr = "2017-05-18 16:00:00"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date =…
完成以下代码,判断一个整数是否是奇数: public boolean isOdd(int i) 看过<编程珠玑>的人都知道这道题的答案和其中极为简单的道理. 最普遍的风格,如下: 这个函数的定义要求返回一个布尔类型的值.而 if 后面的括号里面的表达式的值也是一个布尔类型的.由此,可进行如下改进: 奇数可以分为正奇数和负奇数.奇数的数学表达形式为 2k+1 (k≠0).由此,优化如下: 简单分析,做出如下改进: 右移一位相当于该数除以2,右移2位相当于该数除以4,结果没有小数位,都是取整. 左…
如果你运行如下代码: 1 2 3 4 Integer a = 1000, b = 1000;  System.out.println(a == b);//1 Integer c = 100, d = 100;  System.out.println(c == d);//2 你会得到以下运行结果: 1 2 false true 我们知道,如果两个引用指向同一个对象,那么==就成立:反之,如果两个引用指向的不是同一个对象,那么==就不成立,即便两个引用的内容是一样的.因此,结果就会出现false.…
说出一些常用的类,包,接口,请各举5个 常用的类:BufferedReader  BufferedWriter  FileReader  FileWirter  String Integer java.util.Date,System,Class,List,HashMap 常用的包:java.lang  java.io  java.util   java.sql ,javax.servlet,org.apache.strtuts.action,org.hibernate 常用的接口:Remote…
Introduction to Java Programming 的最后一章,完结撒花!Chapter 17 Binary I/O Section 17.2 How is I/O Handled in Java?1. Which of the following statements are true?a. A File object encapsulates the properties of a file or a path, but does not contain the methods…