当前位置:首页 » 编程语言 » 修改java

修改java

发布时间: 2022-06-04 19:50:51

‘壹’ 修改java程序

你们是同一个班的,同样的问题,都看到了三次:

这个必须要用线程的同步才可以做,打印星星不能再无条件的打印了

importjava.util.concurrent.Phaser;
publicclassStarPhaserDemo{
publicstaticvoidmain(Stringargs[]){
NewlinePhaserphsr=newNewlinePhaser(4,4);
newStarThread(phsr);
newStarThread(phsr);
newStarThread(phsr);
newStarThread(phsr);
}
}
{
=4;
intnumPhases;
intstarNum=0;
publicNewlinePhaser(intnumParties,intphases){
super(numParties);
numPhases=phases;
this.starNum=firstLineStartNum;
}

publicbooleanonAdvance(intphase,intnumParties){
System.out.println();//printanewline
this.starNum=firstLineStartNum-phase-1;
returnphase==numPhases-1;//stopafternumPhases
}
(){
this.starNum--;
returnthis.starNum>=0;
}
}

{
NewlinePhaserphsr;

StarThread(NewlinePhaserp){
phsr=p;
newThread(this).start();
}

publicvoidrun(){
while(!phsr.isTerminated()){
if(phsr.canPrintStart()){
System.out.print('*');
}
phsr.arriveAndAwaitAdvance();
}
}
}

‘贰’ JAVA我该怎么修改

importjava.util.*;
//注意事项一:类名不要使用Main这种和main方法比较接近或者类似java关键字当类的名字。
publicclassNumsDemo{
publicstaticvoidmain(String[]args){
Scannerinput=newScanner(System.in);
System.out.print("请输入10个数字:");
//注意事项二:LinkedList<Integer>这种方法表明list里面放的都是Integer类型
//(注意不是int,因为int是基本数据类型,不是对象,而Integer就是对象)
LinkedList<Integer>linklist=newLinkedList<Integer>();
for(inti=1;i<=10;i++){
linklist.add(input.nextInt());
}
Iterator<Integer>it=linklist.descendingIterator();
System.out.print("您的10个数字为:");
while(it.hasNext()){
System.out.print(it.next()+"");
}
//注意事项三:Scanner也是一种资源,就好比水龙头,打开了水龙头,用完要记得关闭,养成良好的习惯
input.close();
}
}

‘叁’ 怎么修改JAVA JDK的默认版本

重新设置一下环境变量就行。
在变量名中填"JAVA_HOME"
在变量值中填"D:\Program Files\Java\jdk1.5.0_10"

新建的环境变量为以下三个,分别新建好后就可以测试一下了

JAVA_HOME
D:\Program Files\Java\jdk1.5.0_10

PATH
D:\Program Files\Java\jdk1.5.0_10\bin

CLASSPATH
.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(注前面的点号和分号一定不能丢,还有中间的,后面的分号也不要丢了)

‘肆’ java应该怎么改

一个.java文件中只允许定义一个public的类,而且要求这个类必须和所在的.java文件同名,你在一个文件里定义了2个public的类,把它拆分出来,拆到不同的文件里去

‘伍’ JAVA程序修改

importjava.awt.Dimension;
importjava.awt.Point;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JViewport;
importjavax.swing.Timer;


{
privateJButtonbutton1=newJButton("进程1");
privateJFramef=newJFrame();

privateTimertimer;
privateJLabelview=newJLabel("碎裂得美好");
privateJViewportwindow=newJViewport();

publicfirsttry(Stringtitle)//构造函数
{
super(title);
setSize(800,643);
setLocation(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
button1.setSize(283,200);
button1.setLocation(502,2);
add(button1);
window.setView(view);
window.setSize(50,20);
window.setBounds(2,2,500,200);
f.add(window);

getContentPane().add(window);
//添加鼠标事件
button1.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
JButtonclickedButton=(JButton)e.getSource();
timer.start();
clickedButton.setText("事件等待被添加");
}

});
//添加时间控件
timer=newTimer(100,newActionListener(){
publicvoidactionPerformed(ActionEvente)
{
animate();
}
});
timer.setInitialDelay(0);

}
//构造函数完
Pointanchor=view.getLocation();
privatevoidanimate()
{
DimensionextSize=window.getExtentSize();
DimensionviewSize=view.getPreferredSize();
anchor.x+=5;//设置移速度
view.setLocation(anchor);
window.setViewPosition(anchor);
if(anchor.x>viewSize.width)
anchor.x=-extSize.width;
}

publicstaticvoidmain(Stringargs[])
{
firsttryframe=newfirsttry("我的单进程实验");
frame.setVisible(true);
}
}

‘陆’ Java-方法-程序修改

voidisPrime(){

Scannerscan=newScanner(System.in);

System.out.print("inputaandb:");

inta=scan.nextInt(),b=scan.nextInt(),temp;

for(temp=a*b;a%b!=0;a+=b,b=(a-(a=b))%b);

System.out.println("ouput:"+(temp/b));

}

voidisPrime_(){

Scannerscan=newScanner(System.in);

System.out.print("inputaandb:");

inta=scan.nextInt(),b=scan.nextInt();

for(;a%b!=0;a+=b,b=(a-(a=b))%b);

System.out.println("ouput:"+ b);

}

核心代码就一行,功能和你的一样,望采纳

‘柒’ 如何更改java默认版本

java默认版本是指jdk版本 ?
windows下 就卸载充装新版本就行了,linux解压后配置
# vi /etc/profile

在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL上面增加下面内容
java -versoin //查看当前jdk版本后再安装

export JAVA_HOME=/usr/java/jrockit-jdk1.6.0_37-R28.2.5-4.1.0 //当前JDK的版本文件夹
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

保存退出,执行如下命令立即生效以上环境配置
# source /etc/profile

热点内容
tomcat上传超时 发布:2025-02-09 01:41:42 浏览:483
androidactivity竖屏 发布:2025-02-09 01:41:40 浏览:377
家庭配置怎么合理 发布:2025-02-09 01:36:14 浏览:807
头条军事源码 发布:2025-02-09 01:31:53 浏览:997
androidintent视频 发布:2025-02-09 01:31:43 浏览:858
欧姆龙plc密码如何设置 发布:2025-02-09 01:24:31 浏览:687
php支持jpeg 发布:2025-02-09 01:24:22 浏览:803
反编译去注册码 发布:2025-02-09 01:19:48 浏览:887
安卓如何查找旧密码 发布:2025-02-09 01:17:21 浏览:418
hadoop云存储 发布:2025-02-09 01:02:49 浏览:453