本文目录一览:
java编程问题,请高手帮忙!!
小弟啊,认真学习啊,代码如下:看不懂问我
import java.io.*;
class Rectangle {
static double getArea(double length,double width) //求面积
{
return length*width;
}
static double getPerimeter(double length,double width) //求周长
{
return 2*(length+width);
}
public static void main(String args[]){
double length,width,area,perimeter;
try{
System.out.println("input length:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
length = Double.parseDouble(br.readLine());
System.out.println("input width:");
width= Double.parseDouble(br.readLine());
area=getArea(length,width) ;
perimeter=getPerimeter(length,width);
System.out.println("Area="+String.valueOf(area));
System.out.println("Perimeter="+String.valueOf(perimeter));
}catch(Exception ex){System.out.println(ex.getMessage());};
}
}
求Java高手帮忙编程!
我也不太会,你看看这个程序行吗?
import java.lang.Math.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Sample extends JFrame implements ActionListener{
private JButton jb1 = new JButton("GetNumber");
private JButton jb2 = new JButton("Enter");
private JLabel jl = new JLabel();
private JTextField jf = new JTextField();
private JLabel jl1 = new JLabel();
private int num;
public Sample(){
jl.setSize(100,50);
jl.setLocation(50,0);
this.add(jl);
jf.setSize(50,20);
jf.setLocation(50,50);
this.add(jf);
jb1.setSize(100,30);
jb1.setLocation(30,100);
jb1.addActionListener(this);
this.add(jb1);
jb2.setSize(100,30);
jb2.setLocation(150,100);
jb2.addActionListener(this);
this.add(jb2);
this.add(jl1);
this.setTitle("猜数游戏");
this.setBounds(20,20,300,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //实现关闭按钮
this.setResizable(false);
this.setVisible(true);
}
public void getNum(){
num=(int)(Math.random()*10000);
jl.setText("已经产生了数字:");
jl1.setText("");
}
public void test(){
String y;
int x;
y = jf.getText();
try{
x = Integer.parseInt(y);
if(x == num)
JOptionPane.showMessageDialog(this,"祝贺你,你猜对了!","",JOptionPane.INFORMATION_MESSAGE);
else if(xnum)
jl1.setText(" 数小了");
else
jl1.setText(" 数大了");
}
catch (NumberFormatException e) {
jf.setText("");
jl1.setText(" 请输入数字");
}
}
public void actionPerformed(ActionEvent e){ //实现按钮的事件
if(e.getSource()==jb1)
getNum();
else
if(e.getSource()==jb2)
test();
}
public static void main(String[] agrs){
new Sample();
}
}
JAVA编程,求大神啊,感激不尽!
代码如下:
import java.util.Scanner;
public class App33 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] numbers = new int[8];
for (int i = 0; i numbers.length; i++) {
while ((numbers[i] = scanner.nextInt()) = 0) {
System.out.println("请输入一个正整数: ");
}
}
int sum = 0;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (int i = 0; i numbers.length; i++) {
sum += numbers[i];
if (numbers[i] max) {
max = numbers[i];
}
if (numbers[i] min) {
min = numbers[i];
}
}
float average = sum * 1.0f / numbers.length;
System.out.println("总和:" + sum);
System.out.println("平均值:" + average);
System.out.println("最大值:" + max);
System.out.println("最小值:" + min);
}
}
java一个简单小程序,求高手帮忙编写,万分感谢
class Ball {
public void play() {
System.out.println("玩球儿...");
}
}
class Football extends Ball {
public void play() {
System.out.println("使用足球运动");
}
}
class Basketball extends Ball {
public void play() {
System.out.println("使用篮球运动");
}
}
public class TestMain {
public static void main(String[] args) {
TestMain tm = new TestMain();
tm.testPlay();
}
public void testPlay() {
Ball ball = new Football();
ball.play();
ball = new Basketball();
ball.play();
}
}
/*
D:\javac TestMain.java
D:\java TestMain
使用足球运动
使用篮球运动
*/
java程序,求高手指导
非法参数异常:将容器的父类添加到了自己:
jb.add(jb,""+i);
此行代码不对