
正文
抢票源代码Java,怎么写代码抢票
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Java相关问题,求助源代码
第一种
package com.at.java;
class PIThread extends Thread{
public void run(){
double num=1,PI=0;int i=0;
while(num0.001) {
num=(double)4/(2*i+++1);
if(i%2==0)PI-=num;
else PI+=num;
System.out.println("派的数值为"+PI);
if(num=0.001)System.out.println("××××××××××派的数值计算已经结束××××××××××");
}
}
}
class EThread extends Thread{
public void run(){
double num=1,E=0;int i=1;
while(1/num0.00000001) {
num=num*i++;
E+=1/num;
System.out.println("自然对数E的数值为"+E);
if(1/num=0.00000001)System.out.println("××××××××××自然对数的数值计算已经结束××××××××××");
}
}
}
public class JustTest {
public static void main(String args[]) {
PIThread p=new PIThread();
EThread e=new EThread();
p.start();
e.start();
int sum=0;
for(int i=1;i1001;i++)
{
sum+=i;
System.out.println(sum);
}
System.out.println("×××××××××××××自动求和1到1000已经结束××××××××××××××××");
}
}
第二种
package com.at.java;
class PIThread implements Runnable{
public void run(){
double num=1,PI=0;int i=0;
while(num0.001) {
num=(double)4/(2*i+++1);
if(i%2==0)PI-=num;
else PI+=num;
System.out.println("派的数值为"+PI);
if(num=0.001)System.out.println("××××××××××派的数值计算已经结束××××××××××");
}
}
}
class EThread implements Runnable{
public void run(){
double num=1,E=0;int i=1;
while(1/num0.00000001) {
num=num*i++;
E+=1/num;
System.out.println("自然对数E的数值为"+E);
if(1/num=0.00000001)System.out.println("××××××××××自然对数的数值计算已经结束××××××××××");
}
}
}
public class JustTest {
public static void main(String args[]) {
PIThread p=new PIThread();
EThread e=new EThread();
Thread t1=new Thread(p);
Thread t2=new Thread(e);
t1.start();
t2.start();
int sum=0;
for(int i=1;i1001;i++)
{
sum+=i;
System.out.println(sum);
}
System.out.println("×××××××××××××自动求和1到1000已经结束××××××××××××××××");
}
}
都已经验证过,正常运行
相关问答
Q1: 使用Java做一个走马灯,源代码?
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JViewport;
import javax.swing.Timer;
public class Test84 extends JFrame {
private Timer timer;
private JLabel view;
private JViewport window;
public static void main(String[] args)
{
JFrame frm = new Test84("跑马灯");
frm.setDefaultCloseOperation(EXIT_ON_CLOSE);
frm.pack();
frm.setVisible(true);
}
public Test84(String title) throws HeadlessException
{
super(title);
initComponents();
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e)
{
anchor = new Point();
anchor.x = -window.getExtentSize().width;
timer.start();
}
});
timer = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e)
{
animate();
}
});
timer.setInitialDelay(0);
}
private void initComponents()
{
String s = JOptionPane.showInputDialog(null, "请输入要实现效果的文字:");
view = new JLabel(s);
view.setFont(Font.decode("Dialog-BOLD-36"));
view.setForeground(Color.BLUE);
window = new JViewport();
window.setView(view);
getContentPane().add(window);
}
Point anchor;
private void animate()
{
Dimension extSize = window.getExtentSize();
Dimension viewSize = view.getPreferredSize();
anchor.x += 5;//设置移动的速度
window.setViewPosition(anchor);
if (anchor.x viewSize.width)
anchor.x = -extSize.width;
}
}
Q2: 用JAVA怎么写一个秒杀器。求具体代码
最好不要用java写秒杀器,因为你就算用 httpclient 拿到的也是未经过渲染的html页面,很多页面js都没有加载,你根本不知道渲染之后的页面长什么样子,你最好学学木鱼的火车票抢票助手,他用的是 firefox 的插件 scriptish 来写抢票脚本,其实抢票跟秒杀是一个原理的,我第一个秒的程序就是照着他的程序改的,用这个上手也比较容易,但是要求你对javascript比较熟悉,不过比用java实现靠谱多了
Q3: 毕业设计是基于java火车抢票软件开发,思路不清晰,求指点下。
这种东西一般是先去分析12306网站,了解每一步操作的http请求,然后通过java去模拟这些请求就可以了。
但是抢票软件的关键是在于破解其验证码系统,如果这个做不到的花,那么你的东西跟12306没什么区别,没什么价值。现在12306网站验证码变的比较勤,这个难度还是比较大的
多线程似乎也没什么用,都阻塞在了验证码输入上,快不了~ 除非破解验证码
Q4: 手头又一份完整的基于JAVA的B/S航空预订系统的源代码 怎么让他运行起来啊 被人小白~ -。-
Myeclipse下,Files-Import,在General下面选择Existing Projects into Workspace,点击next,在Select root directory下打开项目文件夹的路径,Finish。就OK了。然后在Run as-Java Application.
Q5: java中如何根据一个网址获得该网页的源代码?
package test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpTest {
private String u;
private String encoding;
public static void main(String[] args) throws Exception {
HttpTest client = new HttpTest("", "UTF-8");
client.run();
}
public HttpTest(String u, String encoding) {
this.u = u;
this.encoding = encoding;
}
public void run() throws Exception {
URL url = new URL(u);// 根据链接(字符串格式),生成一个URL对象
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();// 打开URL
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream(), encoding));// 得到输入流,即获得了网页的内容
String line; // 读取输入流的数据,并显示
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
根据具体问题类型,进行步骤拆解/原因原理分析/内容拓展等。
具体步骤如下:/导致这种情况的原因主要是……







