代碼如下:
創(chuàng)新互聯(lián)公司是創(chuàng)新、創(chuàng)意、研發(fā)型一體的綜合型網(wǎng)站建設(shè)公司,自成立以來(lái)公司不斷探索創(chuàng)新,始終堅(jiān)持為客戶提供滿意周到的服務(wù),在本地打下了良好的口碑,在過(guò)去的十載時(shí)間我們累計(jì)服務(wù)了上千家以及全國(guó)政企客戶,如發(fā)電機(jī)回收等企業(yè)單位,完善的項(xiàng)目管理流程,嚴(yán)格把控項(xiàng)目進(jìn)度與質(zhì)量監(jiān)控加上過(guò)硬的技術(shù)實(shí)力獲得客戶的一致贊譽(yù)。
public class HelloWorld {
public static void main(String []args) {
int a = 3, b = 7 ;
?System.out.println("Hello World!");
}
public static int f(int a, int b){
return a*a + a*b + b*b;
}
}
結(jié)果如下:
求素?cái)?shù),比較經(jīng)典的,下面是代碼及注釋
================================================
public class Sushu {
/**
* 判斷一個(gè)數(shù)是不是素?cái)?shù)
* @param a 被判斷的數(shù)
* @return 是素?cái)?shù)返回真
*/
public boolean isSuhu(int a){
boolean isSushu=true;
//根據(jù)素?cái)?shù)的性質(zhì)判斷一個(gè)數(shù)是否為素?cái)?shù)
for(int i=2;ia;i++){
if(a%i==0){
isSushu=false;
break;
}
}
return isSushu;
}
/**
* 判斷連續(xù)若干個(gè)數(shù)中那些是素?cái)?shù)
* @param start 起始數(shù)
* @param end 終止數(shù)
*/
public void selectSushu(int start,int end){
//判斷一串?dāng)?shù)中那些為素?cái)?shù),并將結(jié)果打印出來(lái)
for(int i=start;i=end;i++){
if(isSuhu(i)){
System.out.println(i);
}
}
}
public static void main(String []args){
//定義起始位置和終止位置
int start=1;
int end=100;
//聲明變量
Sushu s=new Sushu();
//調(diào)用方法
s.selectSushu(start, end);
}
}
import?java.applet.Applet;
import?java.awt.Button;
import?java.awt.Color;
import?java.awt.Graphics;
import?java.awt.TextField;
import?java.awt.event.ActionEvent;
public?class?Nicki?extends?Applet{
private?static?final?long?serialVersionUID?=?1L;
private?Button?ok;
private?int?num=32;
private?int?resu=0;
private?boolean?isRig=false;
private?TextField?iPut;
public?Nicki(){
this.setLayout(null);
ok=new?Button("OK");
ok.setActionCommand(getName());
ok.setBounds(150,?150,?40,?20);
iPut=new?TextField();
this.add(iPut);
iPut.setBounds(100,?150,?40,?20);
this.add(ok);
ok.addActionListener(new?ButtonAction(this));
}
public?void?paint(Graphics?g){
g.setColor(Color.white);
g.fillRect(0,?0,?this.getWidth(),?this.getHeight());
g.setColor(Color.BLACK);
g.drawString("Please?guess?a?number?",?10,?20);
g.drawString("between?1?and?100",?10,?40);
if(isRig==falseresu!=0){
if(resunum){
g.drawString(""+resu+"?is?too?big?!",?10,?100);
}else?if(resunum){
g.drawString(resu+"is?too?small?!",?10,?100);
}
}else?if(isRig==true){
g.setColor(Color.GREEN);
g.drawString("Yes,"+resu+"?is?the?right?number",?10,?80);
g.drawString("Your?are?great!?",?10,?100);
g.setColor(Color.red);
g.drawString(resu+"!",?70,?120);
}
iPut.setText("");
g.drawString("Input?the?number:",?0,?150);
}
public?void?ButtonActionPerformed(ActionEvent?e){
if(e.getActionCommand().equals("panel0")){
resu=Integer.parseInt(iPut.getText());
if(num==resu){
isRig=true;
}else{
isRig=false;
}
repaint();
}
}
}
class?ButtonAction?implements?java.awt.event.ActionListener{
Nicki?su;
public?ButtonAction(Nicki?bun){
this.su=bun;
}
public?void?actionPerformed(ActionEvent?e)?{
su.ButtonActionPerformed(e);
}
}