资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

矩形计算器java代码 矩形算法

矩形面积计算器代码怎么写

一、首悉宽瞎先弄清公式:S(面积)=a(长)×b(宽);这应该是最简单的公式了。

网站设计制作过程拒绝使用模板建站;使用PHP+MYSQL原生开发可交付网站源代码;符合网站优化排名的后台管理系统;成都网站建设、网站制作收费合理;免费进行网站备案等企业网站建设一条龙服务.我们是一家持续稳定运营了10余年的成都创新互联网站建设公司。

二、明确输巧铅入,既然是求面积,必须知道长和宽,把它们作为输入项。

三、睁空模块划分:计算过程封装到函数int RecArea(int rec_length, int rec_width);

四、实现如下:

#include stdlib.h

#include stdio.h

// 计算矩形面积

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("输入矩形的长和宽(用逗号分隔):");

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

area = RecArea(length, width);

printf("矩形面积为:%d\n", area);

return 0;

}

java如何写一个计算图形面积的计算器?

参考这中厅迅个框架来写:

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("请选择(1-5):");

try {

answer = input.nextInt();

} catch (NumberFormatException e) {

answer = -1;

}

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

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

System.out.print("编号:");

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);

//插入伏高数据库

DBOperation.addCustomer(customer);

}

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

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

System.out.print("请选择待修改客户编号(-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);

//数据库修改

DBOperation.changeCustomer(newCustomer);

}

else if(answer == 3){

System.out.println("--------删除客户---------");

System.out.print("请选择待删除客户编号(-1退出):");

int cid=input.nextInt();

System.out.print("确认是否删除(Y/N):");

String flag=input.next();

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

CustomerList.delCustomer(cid);

//数据库删除

DBOperation.delCustomer(cid);

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

}

}

else if(answer == 4){

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

ListCustomer all = DBOperation.queryAllCustomer();

System.out.println("编号\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计算长方形的面积?

//计算矩形的面积

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("请输入合大态慎理的长宽");

return -1;

}

}

public static void main(String[] args) {

//测试 宽:10.0 高:闭空20.0

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

}

}

java编写一个窗体程序,实现计算矩形的面积,当用户分别在长和宽编辑框里输入数值

加点分,我帮你

算了,我给你写吧

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

网页链接

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("长:");

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("计算");

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("请输入数字!");

}

}

});

}

}


网站栏目:矩形计算器java代码 矩形算法
当前链接:http://cdkjz.cn/article/ddpjdho.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220