可以使用数组,来存储输入的3个数字,然后排序,得到最大值
创新互联公司是网站建设技术企业,为成都企业提供专业的做网站、成都做网站,网站设计,网站制作,网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制适合企业的网站。10多年品质,值得信赖!
也可以直接一边输出一边判断,参考代码如下
import java.util.Scanner;
public class Exam {
public static void main(String[] args) {
int len =3;
System.out.println("请输入"+len+"个数字");
Scanner sc = new Scanner(System.in);
int max = sc.nextInt();//假设第一次输入的数字是最大,存在这里
for (int i = 0; i len-1; i++) {
int x = sc.nextInt();
if(xmax){//如果比max还要大.那么就替换掉max的值
max = x;
}
}
System.out.println("最大的数字是"+max);
}
}
测试
请输入3个数字
2
1
6
最大的数字是6
有三个问题吧:
import javax.swing.JApplet;
是 extends JApplet
应该加一个name.addActionListener(this)
下面是修改后的代码,我运行过了
import java.awt.*;
import javax.swing.JApplet;
import java.awt.event.*;
public class Applet1 extends JApplet implements ActionListener{
TextField name=new TextField(30);
TextField pw=new TextField(30);
TextField pw1=new TextField(30);
Label la1=new Label();
Label la2=new Label();
Label la3=new Label();
public void actionPerformed(ActionEvent e) {
if(e.getSource()==pw)
pw1.setText(pw.getText());
else if(e.getSource()==name)
name.setText("i know :"+name.getText());
}
public void init(){
this.setLayout(new FlowLayout());
la1.setText("姓名:");
this.add(la1);
this.add(name);
la2.setText("密码:");
this.add(la2);
pw.setEchoChar('*');
this.add(pw);
pw.addActionListener(this);
name.addActionListener(this);
la3.setText("显示密码:");
this.add(la3);
this.add(pw1);
}
}
呵呵!
代码如下:
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;
}
}
结果如下:
1.JavaPow.java
import java.util.Scanner;
public class JavaPow {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个数求平方:");
double num = sc.nextDouble();
System.out.println(num + "的平方结果是:" + Math.pow(num, 2));
}
}
2.CompareTest.java
public class CompareTest {
public static void main(String[] args) {
int a = 10, b = 8;
if(ab){
System.out.println("排序结果是:"+b+"\t"+a);
}else{
System.out.println("排序结果是:"+a+"\t"+b);
}
}
}
3.RateMoney.java
import java.util.Scanner;
public class RateMoney {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double money=0;
double rate=0;
System.out.print("请输入汇款金额:");
money=sc.nextDouble();
if(money0){
rate=0;
}
else if(money0money=100){
rate=1;
}else if(money100money=5000){
rate=money/100;
}else{
rate=50;
}
System.out.println("汇"+money+"元钱需汇款费:"+rate+"元");
}
}
三个都已经写出来了..
你好好看看吧!!
祝你早日成功!
package com.demo;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class TimerTest {
private Timer timer;
private JTextField field;
private JButton button;
private boolean flag = true;
public TimerTest() {
timer = new Timer();
addview();
}
private void addview() {
JFrame frame = new JFrame("Timer test");
field = new JTextField();
field.setPreferredSize(new Dimension(0, 30));
button = new JButton("start");
button.setPreferredSize(new Dimension(100, 30));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (flag) {
auto();
flag = false;
button.setText("stop");
} else {
timer.cancel();
flag = true;
button.setText("start");
}
}
});
frame.add(field, BorderLayout.CENTER);
frame.add(button, BorderLayout.EAST);
frame.setBounds(200, 200, 300, 60);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TimerTest();
}
private void auto() {
timer.schedule(new TimerTask() {
@Override
public void run() {
int num = Integer.parseInt(field.getText().trim());
num += 1;
field.setText(num + "");
auto();
}
}, 1000);
}
}