S********s 发帖数: 29 | 1 A java version:
import java.util.HashSet;
import java.util.Set;
public class DecimalToString {
public static void main(String[] args) {
System.out.println(get_decimal(1, 6));
System.out.println(get_decimal(1, 3));
System.out.println(get_decimal(1, 2));
System.out.println(get_decimal(1, 8));
System.out.println(get_decimal(2, 3));
System.out.println(get_decimal(1, 9));
System.out.println(get_decimal(1, 11));
System.out.println(get... 阅读全帖 |
|
n****i 发帖数: 1024 | 2 主要是第一个comment那边,输入yes or no 然后取出第一个char赋值给tryAgain,我
用了tryAgain = scan.findInLine(".").charAt(0); 跑下来是出现一个框,根本就没
有赋值给tryAgain,求大神帮忙指点下,我哪里出错了。另外我用switch没问题吧
import java.util.Scanner;
import java.util.Random;
public class RockPaperScissors {
private static String[] choices = { "Rock", "Paper", "Scissors" };
public static void main (String[] args){
Scanner scan = new Scanner(System.in);
Random rGen = new Random();
String name;
int playerChoiceNum;
String playerC... 阅读全帖 |
|
J*****v 发帖数: 314 | 3 终于做出来了,这题用来刷掉三哥效果最好
public class Solution {
public boolean minSquaredSmallerThanMax(int[] nums) {
int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
for (int num : nums) {
min = Math.min(min, num);
max = Math.max(max, num);
}
return (long) min * min < max;
}
public int minDelectionFromFront(int[] nums) {
if(minSquaredSmallerThanMax(nums)) {
return 0;
}
int len = nums.length;
do... 阅读全帖 |
|
f*******n 发帖数: 12623 | 4 Java也是一模一样:
Object a = 1;
System.out.println(System.identityHashCode(a)); // prints 1627674070
Object b = a;
System.out.println(System.identityHashCode(b)); // prints 1627674070
b = 5;
System.out.println(System.identityHashCode(b)); // prints 1360875712
System.out.println(a); // prints 1
Object c = 5;
System.out.println(System.identityHashCode(c)); // prints 1360875712
System.out.println(b == c); // prints true
(其实那个b == c不一定要是true。但是很巧Python和Java都缓存小的整数。如果你用
大一点的数字,好像500,Python和Java都会说false的。)
... 阅读全帖 |
|
e********2 发帖数: 495 | 5 public class Solution {
public int[] deleteTree(int[] nums, int ind) {
if(ind == nums[ind]) return new int[0];
int max = Integer.MAX_VALUE;
nums[ind] = max;
int j, k, temp;
for(int i = 0; i < nums.length; ++i){
j = i;
while(nums[j] != j && nums[j] != max && nums[j] >= 0
){
j = nums[j];
}
if(nums[j]... 阅读全帖 |
|
n********n 发帖数: 529 | 6 这是我当时写的,1个半小时左右吧。
/////////////////////////////////////////////////////
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.HashSet;
public class TestForSalesforce {
// Variable to track the dependencies
HashMap> deps = new HashMap
String>>();
// Variable to track the installed commands
HashMap ins = new HashMap();
public boolean... 阅读全帖 |
|
c******1 发帖数: 37 | 7 public class RandomBlack {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
RandomBlack fac = new RandomBlack();
List> lss = fac.permu(9);
for(List ls : lss) {
for(int i = 1; i < 10; i++) {
int getRan = fac.getRan(ls, i);
int check = fac.check(ls, i);
if(getRan == check) continue;
else {
Sys... 阅读全帖 |
|
S*******C 发帖数: 822 | 8 import java.util.Stack;
/*
* Given Tree and Node n and int k, print all node which are at physical
distance <=k from n
* @Amazon intern
*/
public class Solution {
public static void main(String args[]){
Solution solution = new Solution();
TreeNode a = new TreeNode(8);
TreeNode b = new TreeNode(6);
TreeNode c = new TreeNode(10);
TreeNode d = new TreeNode(9);
TreeNode e = new TreeNode(12);
TreeNode f = new TreeNode(4);
TreeNode ... 阅读全帖 |
|
t********n 发帖数: 611 | 9 import java.util.HashMap;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.File;
import java.util.*;
public class Cluster4{
public static void main(String args[]) throws FileNotFoundException,
IOException{
long startTime = System.currentTimeMillis();
String line;
String path = "/Users/***/documents/java/coursera_2/week_2/
problem_2/clustering_big.txt";
File nodeFile = ne... 阅读全帖 |
|
h*********e 发帖数: 247 | 10 try this, all clear.
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadExample
{
public static volatile AtomicInteger count = new AtomicInteger(0);
public static Object lock = new Object();
/**
* @param args
*/
public static void main(String[] args)
{
Runnable a = new Runnable() {
@Override
public void run()
{
synchronized(lock)
{
System.out.println("A ... 阅读全帖 |
|
S****h 发帖数: 115 | 11 sungod介绍的很详细了,我再给补两句,为了新手更容易理解些。毕竟自己也是由新手
过来的。
jsp确实就是servlet,但是既然有了servlet(web server里面用来处理httprequest的
对象),为什么又有jsp呢?
其实servlet本身就是一个java class, 它接受http request然后返回一段html文本。
e.g.
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println(" ... 阅读全帖 |
|
s*********3 发帖数: 389 | 12 I wrote some Java code afterwards. It seems not very clean. Please comment.
import java.util.*;
//Assumptions:
//1. We can move either up or down or left or right at any point in time,
but not diagonally.
//2. One item in the matrix can not be used twice to compose of the pattern
string.
//3. If different routes lead to the same indexes of matrix items to compose
of the pattern string, display them.
//4. The maximum number of movable steps is (matrix.length - 1) + (matrix[0]
.length - 1) = matri... 阅读全帖 |
|
p*******e 发帖数: 186 | 13 我需要登录一个网站,输入用户名和密码,然后下载登录后的网页内容。请问Java如何
能做到?
我在网上找到下面一段代码,但好像不工作,不知道什么原因。版主请手下留情,这里
高手多。我刚学Java。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
public class AuthDemo {
public static void main(String args[]) throws MalformedURLException,
IOException {
String urlString = "";
St... 阅读全帖 |
|
M******1 发帖数: 90 | 14 import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class UberTest {
List data = new ArrayList<>();
public void fillData(){
//Use integer to denote Time here.. you can change it to DateTime
type.
data.add(new TimedKvPair(new KvPair("name1","Bnn"), 1) );
data.add(new TimedKvPair(new KvPair("name2","Dee"), 2) );
data.add(new Time... 阅读全帖 |
|
f****e 发帖数: 923 | 15 class ListNode{
int val;
ListNode next;
ListNode(int val){
this.val = val;
}
}
class Solution{
public int live(int n, int k){
ListNode head = new ListNode(1);
ListNode node = head;
for(int i = 2; i <= n; i++){
node.next = new ListNode(i);
node = node.next;
}
node.next = head;
System.out.println("before remove");
printList(head);
System.out.println("removing the nodes");
whi... 阅读全帖 |
|
h**********c 发帖数: 4120 | 16 这个题编的不太好,
我可以看到在如下的程序,
CoffeeSize的constructor 被call了四次,
加上values()返回的一个array,所以认为是五个objects,
但读了java api 关于enum,发现enum的水很深。
而且enum不能嵌入initialization blocks whether static or not.
不过考试的五十+道题基本都是这样莫名其妙,真的是头大。
enum CoffeeSize{
//! static {
//};
//! {
//
// };
SMALL(6), BIG(10), MEDIUM(8), EXTRA(12) {
public int getSize() {
return 12*2;
}
};
private int size =5;
CoffeeSize(int size) {
System.out.println(size+" CoffeeSize ");
... 阅读全帖 |
|
n******1 发帖数: 3756 | 17 为什么我这里的literal string 和我的封装类equals不上呢,放进set里面也说不相同
,但是hashcode是相等
import java.util.HashSet;
import java.util.Set;
public class SetTesting{
static class WrapString{
String str;
public WrapString(String str){
this.str = str;
}
@Override
public String toString(){
return str;
}
@Override
public int hashCode(){
return str.hashCode();
}
@Override
p... 阅读全帖 |
|
p*******e 发帖数: 186 | 18 【 以下文字转载自 JobHunting 讨论区 】
发信人: pulselite (oOOo), 信区: JobHunting
标 题: 这里人多,请问Java如何读取需要登录的网页的内容
发信站: BBS 未名空间站 (Wed Jan 1 12:52:21 2014, 美东)
我需要登录一个网站,输入用户名和密码,然后下载登录后的网页内容。请问Java如何
能做到?
我在网上找到下面一段代码,但好像不工作,不知道什么原因。版主请手下留情,这里
高手多。我刚学Java。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
publi... 阅读全帖 |
|
d****n 发帖数: 1637 | 19 献给gopher们,俺还没踩到,不过惊出一身冷汗。希望对其他gopher有用
http://studygolang.com/articles/5188
坑(s)
每种编程语言都有自己的专属坑(s),Go虽出身名门,但毕竟年轻,坑也不少,在error
处理这块也可以列出几个。
1、 Go FAQ:Why is my nil error value not equal to nil?
type MyError string
func (e *MyError) Error() string {
return string(*e)
}
var ErrBad = MyError("ErrBad")
func bad() bool {
return false
}
func returnsError() error {
var p *MyError = nil
if bad() {
p = &ErrBad
}
return p // Will always return a non-nil error.
}
func main() {... 阅读全帖 |
|
h**********c 发帖数: 4120 | 20 import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class MonthEndWeekEnd {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
// get the beginning of time, it is the design of modern operating
// system 0 timestamp.
cal.setTimeInMillis(0l);
Date d = cal.getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy
EEE");
String str = dateFormatter.forma... 阅读全帖 |
|
h**********c 发帖数: 4120 | 21 import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class MonthEndWeekEnd {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
// get the beginning of time, it is the design of modern operating
// system 0 timestamp.
cal.setTimeInMillis(0l);
Date d = cal.getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy
EEE");
String str = dateFormatter.forma... 阅读全帖 |
|
e*******o 发帖数: 2271 | 22 原英语版本
My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest and snow,they said
russia could never be tamed.Now they say nothing.They fear me ,like a force
of nature,a dealer in thunder and death.I say I am Napoleon,I am emperor....
....Burn it.
正常翻译版
我树敌无数,却从未逢对手。在橄榄树荫下,他们说意大利永远不会被征服。在法老和
国王的土地上,他们说埃及永远不会臣服。在森林与暴雪的国度,他们说俄国永远不会
被征服。现在他们已无话可说。他们畏惧我... 阅读全帖 |
|
h******8 发帖数: 3624 | 23 【 以下文字转载自 AudioBook 讨论区 】
发信人: Sake09 (小酒), 信区: AudioBook
标 题: ZT: 理科生们,让你们看看神马是文科帝!
发信站: BBS 未名空间站 (Sun Mar 11 12:37:07 2012, 美东)
亮点在最后的方言版。。。
理科生们,让你们看看神马是文科帝!
原英语版本:
“My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest and snow,they said
russia could never be tamed.Now they say nothing.They fear me ,like a force
of nature,a dealer in thunde... 阅读全帖 |
|
i*******n 发帖数: 114 | 24 你能否把这段code做成可编译的C++或java代码,运行一下就知道对不对了。
我做了一个Java的。
结果是
“pylhtesy aatsfoe psaatn ifsyo”
和要求的
“pylhssrtnaatareyeopsfefasmeietawodny”
从第五位字符开始就不对。
但是按照题目的第一行pattern的话,第五位应该是t啊。
1 3 6 10 15 21 ....
public static String parseEncodedString(String inputString){
int numOfRows = 4;
String trimmedInputString = inputString.trim();
trimmedInputString = trimmedInputString.replace(" ", "");
trimmedInputString = trimmedInputString.replace(".", "");
tri... 阅读全帖 |
|
l**h 发帖数: 893 | 25 实现两个函数: H() and O(), 这两个函数会被多线程调用。当一个线程调用H或O时
,如果当前已经有至少两个线程call H和一个线程call O。那么让两个call H和一个
call O的线程返回(产生一个水分子),其他的都block。
写了个Java版本的,大家指教:
import java.util.*;
import java.util.concurrent.*;
public class ThreadH2OSema {
private final Semaphore hCalled = new Semaphore(0);
private final Semaphore hUsed = new Semaphore(0);
private final Semaphore oCalled = new Semaphore(0);
private final Semaphore oUsed = new Semaphore(0);
public void H() {
try {
h... 阅读全帖 |
|
l**h 发帖数: 893 | 26 实现两个函数: H() and O(), 这两个函数会被多线程调用。当一个线程调用H或O时
,如果当前已经有至少两个线程call H和一个线程call O。那么让两个call H和一个
call O的线程返回(产生一个水分子),其他的都block。
写了个Java版本的,大家指教:
import java.util.*;
import java.util.concurrent.*;
public class ThreadH2OSema {
private final Semaphore hCalled = new Semaphore(0);
private final Semaphore hUsed = new Semaphore(0);
private final Semaphore oCalled = new Semaphore(0);
private final Semaphore oUsed = new Semaphore(0);
public void H() {
try {
h... 阅读全帖 |
|
S*******C 发帖数: 822 | 27 我已经写了一个,请大家看一下还有什么可以改进的地方
package design_a_pizza_maker;
/*
* @ServiceNow onsite
*/
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
public class PizzaMaker extends Stopwatch{
public static void main(String[] args) {
PizzaMaker pizzamaker = new PizzaMaker();
Scanner sc = new Scanner(System.in);
System.out.println("Input a to add 30 seconds to current baking
schedule");
System.out.println("Input c to cancel current baking schedule");... 阅读全帖 |
|
l*****o 发帖数: 214 | 28 public class NumberPickGame {
public NumberPickGame() {}
public static boolean canIForceWin(int maxNumber, int total) {
if ((maxNumber + 1) * maxNumber /2 < total) {
return false;
}
Set numbersAvailable = new HashSet();
for (int i = 1; i <= maxNumber; i++) {
numbersAvailable.add(i);
}
int[] picks = new int[maxNumber];
boolean canWin = canFirstPlayerWin(numbersAvailable, total, 0, pic... 阅读全帖 |
|
z****e 发帖数: 54598 | 29
下面的输出结果是什么?
int a = 3, b = 3;
Integer aa = new Integer(3), bb = new Integer(3);
Integer cc = aa;
System.out.println(a==b);
System.out.println(aa==bb);
System.out.println(aa==cc);
System.out.println(aa.equals(bb));
System.out.println(aa.equals(cc));
System.out.println(aa.equals(a));
System.out.println(aa==a); |
|
c********t 发帖数: 5706 | 30 这个是完整测试代码,有兴趣的可以跑跑试试
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class BlockingQueue {
private List queue;
private int limit;
public BlockingQueue(int pLimit) {
this.limit = pLimit;
queue = new LinkedList();
}
public synchronized void enqueue(T item) throws InterruptedException {
try {
if (this.queue.size() == this.limit)
System.out.println("wait, enque " + item);
... 阅读全帖 |
|
t******d 发帖数: 1383 | 31 做了个望上的测试,结果昨天晚上做了,今天被据了。请刷了poj的看看。 这哪里还有
bug?
跑出来的结果是
the number 007 is a number: false
the number 0.5 is a number: true
the number .01 is a number: true
the number 9. is a number: true
the number 1.000 is a number: true
the number 00.5 is a number: false
the number -.005000 is a number: true
我看着没问题
public class IsNumber {
/**
* The IsNumber function takes a String and returns true if that string
is a number, and false otherwise.
* This implementation, however, has several bugs in ... 阅读全帖 |
|
l**********o 发帖数: 9952 | 32 网友真的很有才啊
原英语版本
My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest and snow,they said
russia could never be tamed.Now they say nothing.They fear me ,like a force
of nature,a dealer in thunder and death.I say I am Napoleon,I am emperor....
....Burn it.
正常翻译版
我树敌无数,却从未逢对手。在橄榄树荫下,他们说意大利永远不会被征服。在法老和
国王的土地上,他们说埃及永远不会臣服。在森林与暴雪的国度,他们说俄国永远不会
被征服。现在他们... 阅读全帖 |
|
m*f 发帖数: 8162 | 33 【 以下文字转载自 Joke 讨论区 】
发信人: zoun (zoun), 信区: Joke
标 题: ZT: 理科生们,让你们看看神马是文科帝! (转载)
发信站: BBS 未名空间站 (Fri Mar 16 14:36:49 2012, 美东)
发信人: andyzzdlee (大院豚鼠), 信区: LeisureTime
标 题: ZT: 理科生们,让你们看看神马是文科帝! (转载)
发信站: BBS 未名空间站 (Thu Mar 15 02:25:20 2012, 美东)
发信人: Sake09 (小酒), 信区: AudioBook
标 题: ZT: 理科生们,让你们看看神马是文科帝!
发信站: BBS 未名空间站 (Sun Mar 11 12:37:07 2012, 美东)
亮点在最后的方言版。。。
理科生们,让你们看看神马是文科帝!
原英语版本:
“My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.... 阅读全帖 |
|
V**********1 发帖数: 24381 | 34 理科生膜拜的文科帝的翻译
英语版本:“My enemies are many,my equals are none. In the shade of olive
trees,they said Italy could never be conquered.In the land of pharoahs and
kings, they said Egypt could never be humbled.In the realm of forest and
snow,they said russia could never be tamed.Now they say nothing.They fear me
,like a force of nature,a dealer in thunder and death.I say I am Napoleon,I
am emperor........Burn it”
文言文版:
朕之仇寇多矣,然敌手则未之有也。大秦、大食、罗刹,皆自诩不可胜之,而今寂然。
彼畏朕,犹若畏天。朕,天之子也……焚!
评书版:
话说朕的敌人那~叫一个品种繁多啊,可咋样?... 阅读全帖 |
|
d********a 发帖数: 1947 | 35 这个奥特没?
英语版本:“My enemies are many,my equals are none. In the shade of olive
trees,they said Italy could never be conquered.In the land of pharoahs and
kings, they said Egypt could never be humbled.In the realm of forest and
snow,they said russia could never be tamed.Now they say nothing.They fear me
,like a force of nature,a dealer in thunder and death.I say I am Napoleon,I
am emperor........Burn it”
文言文版:
朕之仇寇多矣,然敌手则未之有也。大秦、大食、罗刹,皆自诩不可胜之,而今寂然。
彼畏朕,犹若畏天。朕,天之子也……焚!
评书版:
话说朕的敌人那~叫一个品种繁多啊,可咋样?都被朕连锅端... 阅读全帖 |
|
S****9 发帖数: 8108 | 36 亮点在最后的方言版。。。
理科生们,让你们看看神马是文科帝!
原英语版本:
“My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest and snow,they said
russia could never be tamed.Now they say nothing.They fear me ,like a force
of nature,a dealer in thunder and death.I say I am Napoleon,I am emperor……
..Burn it”
正常翻译版:
“我树敌无数,却从未逢对手。在橄榄树荫下,他们说意大利永远不会被征服。在法老
和国王的土地上,他们说埃及永远不会臣服。在森林与暴雪的国... 阅读全帖 |
|
a********e 发帖数: 3771 | 37 【 以下文字转载自 AudioBook 讨论区 】
发信人: Sake09 (小酒), 信区: AudioBook
标 题: ZT: 理科生们,让你们看看神马是文科帝!
发信站: BBS 未名空间站 (Sun Mar 11 12:37:07 2012, 美东)
亮点在最后的方言版。。。
理科生们,让你们看看神马是文科帝!
原英语版本:
“My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest and snow,they said
russia could never be tamed.Now they say nothing.They fear me ,like a force
of nature,a dealer in thunde... 阅读全帖 |
|
a********e 发帖数: 3771 | 38 【 以下文字转载自 AudioBook 讨论区 】
发信人: Sake09 (小酒), 信区: AudioBook
标 题: ZT: 理科生们,让你们看看神马是文科帝!
发信站: BBS 未名空间站 (Sun Mar 11 12:37:07 2012, 美东)
亮点在最后的方言版。。。
理科生们,让你们看看神马是文科帝!
原英语版本:
“My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest and snow,they said
russia could never be tamed.Now they say nothing.They fear me ,like a force
of nature,a dealer in thunde... 阅读全帖 |
|
g********d 发帖数: 506 | 39 原英语版本:“My enemies are many,my equals are none. In the shade of olive
trees,they said Italy could never be conquered.In the land of pharoahs and
kings, they said Egypt could never be humbled.In the realm of forest and
snow,they said russia could never be tamed.Now they say nothing.They fear me
,like a force of nature,a dealer in thunder and death.I say I am Napoleon,I
am emperor........Burn it”
以下为正常翻译版:
“我树敌无数,却从未逢对手。在橄榄树荫下,他们说意大利永远不会被征服。在法老
和国王的土地上,他们说埃及永远不会臣服。在森林与暴雪的国度,他们说俄国永远不
会被征服。现在他们已无话可说。... 阅读全帖 |
|
z**n 发帖数: 22303 | 40 【 以下文字转载自 LeisureTime 讨论区 】
发信人: andyzzdlee (大院豚鼠), 信区: LeisureTime
标 题: ZT: 理科生们,让你们看看神马是文科帝! (转载)
发信站: BBS 未名空间站 (Thu Mar 15 02:25:20 2012, 美东)
发信人: Sake09 (小酒), 信区: AudioBook
标 题: ZT: 理科生们,让你们看看神马是文科帝!
发信站: BBS 未名空间站 (Sun Mar 11 12:37:07 2012, 美东)
亮点在最后的方言版。。。
理科生们,让你们看看神马是文科帝!
原英语版本:
“My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest an... 阅读全帖 |
|
D*****d 发帖数: 1307 | 41 I wrote some java code, might be ugly, but it works...
package Testing;
public class TestReplaceWithQuotes {
public static String replaceInsideQuotes(String source, char quote,
String target, String replacement){
StringBuilder regex = new StringBuilder();
StringBuilder replace = new StringBuilder();
String quoteChar = Character.isDigit(quote) || Character.
isAlphabetic(quote) ? String.valueOf(quote) : ("\" + quote);
String nonQuoteChar = "[^" + quoteCh... 阅读全帖 |
|
l**h 发帖数: 8270 | 42 【 以下文字转载自 Tennessee 讨论区 】
发信人: donnamaria (Virgo Maria, Laetare, Halleluia), 信区: Tennessee
标 题: 理科生膜拜的文科帝的翻译
发信站: BBS 未名空间站 (Tue Oct 18 08:46:05 2011, 美东)
这个奥特没?
英语版本:“My enemies are many,my equals are none. In the shade of olive
trees,they said Italy could never be conquered.In the land of pharoahs and
kings, they said Egypt could never be humbled.In the realm of forest and
snow,they said russia could never be tamed.Now they say nothing.They fear me
,like a force of nature,a dealer in thunder ... 阅读全帖 |
|
t*********e 发帖数: 630 | 43 Is there a better way to do it? The findMaxPalindrome needs to be called
twice.
String maxPalindrome(String str) {
String maxPalindrome = "";
for(int i=0; i
// when the palindrome is odd number, i.e. "aabaa"
maxPalindrome = findMaxPalindrome(str,i,i,maxPalindrome);
// when the palindrom is even number, i.e. "cccc"
maxPalindrome = findMaxPalindrome(str,i,i+1,maxPalindrome);
}
... 阅读全帖 |
|
p*****2 发帖数: 21240 | 44 (defn -main []
(let [c1 (chan) c2 (chan) c3 (chan) c4 (chan) c5 (chan) c6 (chan)]
(go
(
(println "x happened")
(>! c1 10))
(go
(let [a (inc (
(>! c2 a)
(>! c2 a)))
(go
(let [a (
(go
(println "y begin")
(
(println "y happened " a)
(>! c3 20))
(go
(println "z begin")
(
(pri... 阅读全帖 |
|
k*******t 发帖数: 202 | 45 import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Foo {
String name;
int number;
List friends;
public boolean equals(Object obj)
{
System.out.println(friends);
System.out.println(test.friends);
System.out.println(test.name);
System.out.println(this.name);
return number == test.number
&& (name == test.name
|| (name != null && name.equals(... 阅读全帖 |
|
l*******b 发帖数: 2586 | 46 这个循环的测试有些意思,在linux下for比while慢1倍。在windows下20倍。
不过用functional的写法比前两个都快很多
val start = System.currentTimeMillis()
var total = 0
for(i <- 0 until 100000) total += i
val end = System.currentTimeMillis()
println(end-start)
println(total)
val ss = System.currentTimeMillis()
var tt = 0
var i = 0
while(i < 100000) { i = i + 1; tt += i}
val ee = System.currentTimeMillis()
println(ee-ss)
println(tt)
def f(x: Int, sum: Int): Int = if(x == 0) sum else f(x - 1, sum + x)
val mm = System.currentTimeMillis()
val ... 阅读全帖 |
|
p*****2 发帖数: 21240 | 47 class Iterator[T](arr:Array[T]){
private[this] var pos=0
def peek()={
if(pos
}
def pop()={
if(pos
}
def reset(){
pos=0
}
}
object test2 extends App {
val arr=Array(1,2,3,4,5)
val it=new Iterator(arr)
println(it.peek())
println(it.pop())
println(it.peek())
println(it.pop())
println(it.peek())
println(it.pop())
} |
|
p*****2 发帖数: 21240 | 48
object test6 extends App {
val sc=new Scanner(System.in)
val n=sc.nextInt
val m=sc.nextInt
val mat=new Array[String](n)
val start=System.currentTimeMillis()
for(i<-0 until n) mat(i)=sc.next()
def check(i:Int, j:Int, k:Int, l:Int):Boolean={
val minX=math.min(i,k)
val maxX=math.max(i,k)
val minY=math.min(j,l)
val maxY=math.max(j,l)
var minR=true
var maxR=true
var minC=true
var maxC=true
... 阅读全帖 |
|
f********a 发帖数: 165 | 49 import java.util.HashMap;
public class MyClass {
public static HashMap hashMap = new HashMap
Integer>();
private String s = new String();
public void log1(String msg1, String msg2){
synchronized(hashMap){
System.out.println(msg1);
System.out.println(msg2);
}
}
public void log2()
{
hashMap.put(new String("123"), new Integer(1));
}
public static void log3(String ms... 阅读全帖 |
|
m*v 发帖数: 6 | 50 是不是和blockingqueue一个道理啊?
用一个data structure去coordinate两个threads?
public class H2O {
private int hCount;
private int oCount;
public H2O() {
hCount = 0;
oCount = 0;
}
public synchronized void addH() throws InterruptedException {
if(hCount == 2 && oCount == 1) {
System.out.println("add H, H2O");
hCount = 0;
oCount = 0;
notifyAll();
}
else {
while(hCount == 2) {
Syste... 阅读全帖 |
|