真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

矩形計(jì)算器java代碼 矩形算法

矩形面積計(jì)算器代碼怎么寫

一、首悉寬瞎先弄清公式:S(面積)=a(長(zhǎng))×b(寬);這應(yīng)該是最簡(jiǎn)單的公式了。

網(wǎng)站設(shè)計(jì)制作過(guò)程拒絕使用模板建站;使用PHP+MYSQL原生開(kāi)發(fā)可交付網(wǎng)站源代碼;符合網(wǎng)站優(yōu)化排名的后臺(tái)管理系統(tǒng);成都網(wǎng)站建設(shè)、網(wǎng)站制作收費(fèi)合理;免費(fèi)進(jìn)行網(wǎng)站備案等企業(yè)網(wǎng)站建設(shè)一條龍服務(wù).我們是一家持續(xù)穩(wěn)定運(yùn)營(yíng)了10余年的成都創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司。

二、明確輸巧鉛入,既然是求面積,必須知道長(zhǎng)和寬,把它們作為輸入項(xiàng)。

三、睜空模塊劃分:計(jì)算過(guò)程封裝到函數(shù)int RecArea(int rec_length, int rec_width);

四、實(shí)現(xiàn)如下:

#include stdlib.h

#include stdio.h

// 計(jì)算矩形面積

int RecArea(int rec_length, int rec_width)

{

int rec_area = 0;

rec_area = rec_length*rec_width;

return rec_area;

}

int main()

{

int length, width, area;

printf("輸入矩形的長(zhǎng)和寬(用逗號(hào)分隔):");

scanf("%d,%d", length, width);

area = RecArea(length, width);

printf("矩形面積為:%d\n", area);

return 0;

}

java如何寫一個(gè)計(jì)算圖形面積的計(jì)算器?

參考這中廳迅?jìng)€(gè)框架來(lái)寫:

public static void main(String[] args) throws IOException {

Scanner input = new Scanner(System.in);

int exit = 5;

int answer;

do {

System.out.println("--------客戶信息管理軟件---------");

System.out.println("1 添加客戶");

System.out.println("2 修改客戶");

System.out.println("3 刪除客戶");

System.out.println("4 客戶列表"賣此);

System.out.println("5 退出");

System.out.println();

System.out.println("請(qǐng)選擇(1-5):");

try {

answer = input.nextInt();

} catch (NumberFormatException e) {

answer = -1;

}

if(answer == 1){//新增客戶

System.out.println("--------添加客戶---------");

System.out.print("編號(hào):");

int id=input.nextInt();

System.out.print("姓名:");

String name=input.next();

System.out.print("性別:");

String gender=input.next();

System.out.print("年齡:");

int age=input.nextInt();

System.out.print("電話:");

String tel=input.next();

System.out.print("郵箱:");

String email=input.next();

Customer customer=new Customer(id,name,gender,age,tel,email);

//添加:

CustomerList.addCustomer(customer);

//插入伏高數(shù)據(jù)庫(kù)

DBOperation.addCustomer(customer);

}

else if(answer == 2){//修改客戶

System.out.println("--------修改客戶---------");

System.out.print("請(qǐng)選擇待修改客戶編號(hào)(-1退出):");

int cid=input.nextInt();

Customer customer = new CustomerList().queryCustomer(cid);

System.out.print("姓名("+customer.getCostomerName()+"):");

String newName = input.next();

System.out.print("性別("+customer.getGender()+"):");

String newGender = input.next();

System.out.print("年齡("+customer.getAge()+"):");

int newAge = input.nextInt();

System.out.print("電話("+customer.getTel()+"):");

String newTel = input.next();

System.out.print("郵箱("+customer.getEmail()+"):");

String newEmail = input.next();

Customer newCustomer = new Customer(customer.getCustomerID(),newName,newGender,newAge,newTel,newEmail);

CustomerList.changeCustomer(newCustomer);

//數(shù)據(jù)庫(kù)修改

DBOperation.changeCustomer(newCustomer);

}

else if(answer == 3){

System.out.println("--------刪除客戶---------");

System.out.print("請(qǐng)選擇待刪除客戶編號(hào)(-1退出):");

int cid=input.nextInt();

System.out.print("確認(rèn)是否刪除(Y/N):");

String flag=input.next();

if("Y".equalsIgnoreCase(flag)){

CustomerList.delCustomer(cid);

//數(shù)據(jù)庫(kù)刪除

DBOperation.delCustomer(cid);

System.out.println("--------刪除完成---------");

}

}

else if(answer == 4){

System.out.println("--------客戶列表---------");

ListCustomer all = DBOperation.queryAllCustomer();

System.out.println("編號(hào)\t\t姓名\t\t性別\t\t年齡\t\t電話\t\t郵箱\t\t");

for(Customer customer:all){

System.out.print(customer.getCustomerID()+"\t\t"+customer.getCostomerName()+"\t\t"+customer.getGender()+"\t\t"+customer.getAge()+"\t\t"+customer.getTel()+"\t\t"+customer.getEmail()+"\n");

}

System.out.println("--------客戶列表完成---------");

}else if(answer == 5){

System.out.println("歡迎下次使用!");

}

}while(answer != exit);

}

如何用java計(jì)算長(zhǎng)方形的面積?

//計(jì)算矩形的面積

public class RectArea {

public static double getArea(double width, double higth) {

double area = 0.0;// 矩形面積

// 判斷輸滾敬入是否合理

if (!(width = 0 || higth = 0)) {

area = width * higth;

return area;// 返回面積

} else {

System.out.println("請(qǐng)輸入合大態(tài)慎理的長(zhǎng)寬");

return -1;

}

}

public static void main(String[] args) {

//測(cè)試 寬:10.0 高:閉空20.0

System.out.println("矩形面積" + RectArea.getArea(10.0, 20.0));

}

}

java編寫一個(gè)窗體程序,實(shí)現(xiàn)計(jì)算矩形的面積,當(dāng)用戶分別在長(zhǎng)和寬編輯框里輸入數(shù)值

加點(diǎn)分,我?guī)湍?/p>

算了,我給你寫吧

放Ubuntu past了,有效期是1年:

網(wǎng)頁(yè)鏈接

import?java.awt.EventQueue;

import?java.awt.event.ActionEvent;

import?java.awt.event.ActionListener;

import?山判javax.swing.JFrame;

import?javax.swing.JLabel;

import?javax.swing.JTextField;

import?javax.swing.JButton;

public?class?Square?{

private?JFrame?frame;

private?JTextField?textField;

private?JTextField?textField_1;

private?JTextField?逗培改textField_2;

public?static?void?main(String[]?args)?{

EventQueue.invokeLater(new?Runnable()?{

public?void?run()?{

try?{

Square?window?=?new?Square();

window.frame.setVisible(true);

}?catch?(Exception?e)?{

e.printStackTrace();

}

}

});

}

/**

*?Create?the?application.

*/

public?Square()?{

initialize();

}

/**

*?Initialize?the?contents?of?the?frame.

*/

private?void?initialize()?{

frame?=?new?JFrame();

frame.setBounds(100,?100,?235,?315);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

frame.setResizable(false);

JLabel?label?=?new?JLabel("長(zhǎng):");

label.setBounds(27,?31,?27,?41);

frame.getContentPane().add(label);

textField?=?new?JTextField();

textField.setBounds(88,?39,?86,?24);

frame.getContentPane().add(textField);

textField.setColumns(10);

JLabel?label_1?=?new?JLabel("寬:");

label_1.setBounds(27,?85,?27,?41);

frame.getContentPane().add(label_1);

textField_1?=?new?JTextField();

textField_1.setBounds(88,?93,?86,?24);

frame.getContentPane().add(textField_1);

textField_1.setColumns(10);

JLabel?label_2?=?new?JLabel("面積:");

label_2.setBounds(27,?154,?43,?18);

frame.getContentPane().add(label_2);

textField_2?=?new?JTextField();

textField_2.setColumns(10);

textField_2.setBounds(88,?151,?86,?24);

frame.getContentPane().add(textField_2);

JButton?button?=?new?JButton("計(jì)算");

button.setBounds(46,?213,?113,?27);

frame.getContentPane().add(button);

button.addActionListener(new?ActionListener()?{

@Override

public?void?actionPerformed(ActionEvent?e)?{

try?{

Double?d1?=?Double.valueOf(textField.getText());

Double?中鋒d2?=?Double.valueOf(textField_1.getText());

Double?d3?=?(int)?(d1?*?d2?*?1000?+?0.5)?/?1000.0;

textField_2.setText(d3.toString());

}?catch?(Exception?e2)?{

//?TODO:?handle?exception

textField_2.setText("請(qǐng)輸入數(shù)字!");

}

}

});

}

}


網(wǎng)站題目:矩形計(jì)算器java代碼 矩形算法
文章分享:http://weahome.cn/article/ddpjdho.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部