本文目錄一覽:
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);
此行代碼不對
原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/129886.html