百韵网 >>  正文

求编写一个超级简单的Java的程序源代码

来源:www.baiyundou.net   日期:较早时间
你好
很高兴能够回答你的问题。

我帮你实现了一个复数类,并且可以执行复数的加减,乘除你再写两个方法就可以了:
代码如下:

public class complie {
int i,j;
public complie(int i,int j)//构建一个复数类
{
this.i=i;
this.j=j;
}
complie add(complie c)//复数加法
{
int l,k;
l=c.i+i;
k=c.j+j;
return (new complie(l,k));
}
complie cut(complie c)//复数减法
{
int l,k;
l=i-c.i;
k=j-c.j;
return (new complie(l,k));
}
void ToString()//将复数输出
{
System.out.println("复数为:"+i+"+"+j+"i");
}

public static void main(String[] args)
{
complie a=new complie(4,5);
complie b=new complie(2,3);
System.out.println("构造的复数类为:");
a.ToString();
b.ToString();
System.out.println("运算复数a+b=:");
a.add(b).ToString();
System.out.println("运算复数a-b=:");
a.cut(b).ToString();

}
}

运行结果:
--------------------Configuration: <Default>--------------------
构造的复数类为:
复数为:4+5i
复数为:2+3i
运算复数a+b=:
复数为:6+8i
运算复数a-b=:
复数为:2+2i

Process completed.

程序我已经调试通过了的。

希望能帮到你,同时希望你能采纳我的答案,谢谢!

求编写一个超级简单的Java的程序源代码~

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Login {

public static void main(String args[]) {
LoginFrm frame = new LoginFrm();
}
}

class LoginFrm extends JFrame implements ActionListener{
JLabel nameLabel=new JLabel("用户名:");
JLabel pwdLabel=new JLabel("密码:");
JTextField name=new JTextField(10);
JPasswordField password=new JPasswordField(10);
JButton butnSure=new JButton("确定");
JButton butnCancel=new JButton("取消");
public LoginFrm() {
super("登陆");
setBounds(500, 200, 280, 220);
setVisible(true);
setLayout(null);
nameLabel.setBounds(45, 20, 100, 25);
add(nameLabel);
add(name);
name.setBounds(105, 20, 110, 25);
add(pwdLabel);
pwdLabel.setBounds(45, 60, 100, 25);
add(password);
password.setBounds(105, 60, 110, 25);
add(butnSure);
butnSure.setBounds(45, 100, 80, 25);
add(butnCancel);
butnCancel.setBounds(135, 100, 80, 25);
butnSure.addActionListener(this);
butnCancel.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();//刷新
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() ==butnSure){
System.out.println("用户名:"+name.getText());
System.out.println("密码:"+name.getText());
if("admin".equals(name.getText().trim())&&"123".equals(password.getText().trim())){
this.dispose();
new MainFrm("用户界面",name.getText().trim(),password.getText().trim());
}else {
JOptionPane.showMessageDialog(this, "用户不存在");
}
}else if(e.getSource()==butnCancel){
System.exit(1);
}
}

class MainFrm extends JFrame{
private JLabel info;

public MainFrm(String s,String name,String password) {
super(s);
setBounds(400, 200, 500, 400);
setLayout(new FlowLayout());
info=new JLabel("登陆成功,用户名:"+name+",密码:"+password);
add(info);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
}
}

/**
* 用对象的方法打印杨辉三角
*
* @author SunShine
*
*/
public class Exer01 {

public void draw(int h) {
if (h == 0) {
return;
}

if (h > 12) { // 可打印到12行,超过就赋值为可打印最大行数
h = 12;
}

int[][] yh = new int[h][]; // 根据输入值设置二维数组的第一维数

for (int i = 0; i < yh.length; i++) {
yh[i] = new int[i + 1]; // 设置第二维数
yh[i][0] = yh[i][i] = 1; // 对两头的元素赋值为1

for (int j = 1; j < yh[i].length - 1; j++) { // 对中间的元素赋值
yh[i][j] = yh[i - 1][j - 1] + yh[i - 1][j];
}
}

// 打印杨辉三角
for (int i = 0; i < yh.length; i++) {
for (int k = 0; k < h - i - 1; k++) {
System.out.print(" ");
}
System.out.print(yh[i][0] + " ");
for (int j = 1; j < yh[i].length; j++) {
if (yh[i][j] < 10) {
System.out.print(" " + yh[i][j] + " ");
} else if (yh[i][j] < 100) {
System.out.print(" " + yh[i][j] + " ");
} else {
System.out.print(" " + yh[i][j] + " ");
}
}
System.out.println();
}
System.out.println();
}

/**
* @param args
*/
public static void main(String[] args) {
Exer01 test = new Exer01();
test.draw(8);
}

}

1

相关要点总结:

13958708820:求一非常简单的java 程序?
晏骂答:import java.util.Scanner;public class GetNumResult { public static void main(String[] args) { Scanner s = new Scanner(System.in);System.out.println("请输入一个整数:");int num = s.nextInt();for(int i = 1; i <= 10; i ++){ System.out.println(num + " * " + i ...

13958708820:用JAVA编写 简单的程序 求教
晏骂答:import java.util.Scanner;public class Test { public static void main(String[] args) { boolean result = false;do{ System.out.print("请输入整数:");Scanner scan = new Scanner(System.in);long num = scan.nextInt();int[] value = new int[10];//最多10位整数 int i = 0;/...

13958708820:JAVA 编写一个java图形GUI程序,比较大小数并输出
晏骂答:3.接下来生成最大数按钮maxNumberButton和关闭按钮closeButton,并放在界面上。然后让maxnNumberButton监听鼠标单击事件 maxNumberButton.addMouseListener(new MouseAdapter() { if (SwingUtilities.isLeftMouseButton(e)) {//判断是否鼠标左键按下 //在这里获得第一个和第二个数并比较获得最大的数,当然...

13958708820:求JAVA高手写几个简单的小程序
晏骂答:System.out.println("大写个数:" +upCount + "\r\n小写个数:" + dwCount);} / 算出面额的张数 param num / public void calculationNum(double num){ String[] s = {"100","50","20","10","5","1","0.5","0.1","0.05","0.02","0.01"};java.util.Random random =...

13958708820:求一个JAVA应用程序编写的简单ATM代码
晏骂答:import javax.swing.*;import java.awt.event.*;public class SimAtm extends JFrame implements java.awt.event.ActionListener{ private static final long serialVersionUID = 1L;private JButton[] buts = new JButton[4];private String [] tils = new String[] {"存款", "取款", "查询",...

13958708820:编写一个Java应用程序,该程序中有2个类:Trangle、和Circle,分别用来描述...
晏骂答:代码如下:class Triangle {private double a;private double b;private double c;private double perimeter;// 周长private double area;// 面积public Triangle(double a, double b, double c) {this.a = a;this.b = b;this.c = c;this.perimeter = a + b + c;double p = (a + b ...

13958708820:编写一个java程序
晏骂答:import java.util.Arrays;import java.util.Scanner;public class NumArry {public static void main(String[] args) {String str1 = "123,1234,234,533,-34,335,34";String[] ss = str1.split(",");//用逗号切分成字符串数组int[] ary = new int[ss.length];//新建整数数组for (int ...

13958708820:编写一个java Applet程序
晏骂答:import java.applet.Applet;import java.awt.Button;import java.awt.Graphics;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;public class Numberpow extends Applet implements Key...

13958708820:用Java编写一个可以读取和写入txt文档的程序 要求实现可视化的窗口
晏骂答:f.add(ta1);//注册文本区的事件监听程序 ta1.addTextListener(this);p1 = new Panel(); //面板与布局 p1.setLayout(new FlowLayout(FlowLayout.LEFT));b1 = new Button("Open");b2 = new Button("Save");b3 = new Button("Save As");p1.add(b1); //三个按钮挂上面板 p1.add(...

13958708820:编写一个Java程序片断定义一个表示学生的类student,包括域“学号...
晏骂答:} public void setName(String name) { this.name = name;} public String getSex() { return sex;} public void setSex(String sex) { this.sex = sex;} public int getAge() { return age;} public void setAge(int age) { this.age = age;} }这问题很基础的,多看一下吧 ...

(编辑:本站网友)
相关推荐
关于我们 | 客户服务 | 服务条款 | 联系我们 | 免责声明 | 网站地图
@ 百韵网