网站建设资讯

NEWS

网站建设资讯

java程序设计示例代码,java程序设计教程例题代码

JAVA程序设计,大神给个可行的代码,谢谢了!

public class Circle {

创新互联建站坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的东阳网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

private double radiums; //半径

private Point point; //坐标

public Circle(double radium, Point point) {

super();

this.radiums = radium;

this.point = point;

}

public double getRadium() {

return radiums;

}

public void setRadium(double radium) {

this.radiums = radium;

}

public Point getPoint() {

return point;

}

public void setPoint(Point point) {

this.point = point;

}

public  double  getLength(){ //周长

return  2*Math.PI*radiums;

}

public double getArea(){ //面积

return Math.PI*Math.pow(radiums, 2);

}

}

public class Point {

private int x;  //x轴

private int y; //y轴

public Point(int x, int y) {

super();

this.x = x;

this.y = y;

}

public int getX() {

return x;

}

public void setX(int x) {

this.x = x;

}

public int getY() {

return y;

}

public void setY(int y) {

this.y = y;

}

}

public class Test {

public static void main(String[] args) {

Point point = new Point(14,16); //设置坐标

Circle circle = new Circle(5, point); //创建一个圆

double area = circle.getArea();

double length = circle.getLength();

System.out.println("圆的面积是:"+area);

System.out.println("圆的周长是:"+length);

System.out.println("圆的x坐标是: "+point.getX());

System.out.println("圆的y坐标是:"+point.getY());

}

}

输出结果如下:

圆的面积是:78.53981633974483

圆的周长是:31.41592653589793

圆的x坐标是: 14

圆的y坐标是:16

求一个简单java程序代码,谢谢

public class TestStar {

public static void main(String[] args) {

String star = "*";

for (int i = 0; i 5; i++) {

if (i == 0) {

System.out.print(" " + star);

System.out.println();

}

if (i == 1) {

for (int z = 0; z 4; z++) {

System.out.print(" " + star);

}

System.out.println();

}

if (i == 2) {

System.out.print(" ");

for (int x = 0; x 3; x++) {

System.out.print(" " + star);

}

System.out.println();

}

if (i == 3) {

for (int y = 0; y 2; y++) {

System.out.print(" " + star + " ");

}

}

}

}

}

是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)

如何用Java程序编程,最好讲解一下。题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对

这道题目考察的是运用递归(数列)的思路去解决问题。

假设到第24个月,示例代码如下:

public class woo {

public static void main(String args[]) {

System.out.println(fib(24));

}

private static int fib(int n) {

if (n == 1 || n == 2) {

return 1;

} else {

return fib(n - 1) + fib(n - 2);

}

}

}

扩展资料:

斐波那契数列(Fibonacci sequence),又称黄金分割数列、因数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,故又称为“兔子数列”,指的是这样一个数列:1、1、2、3、5、8、13、21、34、……。

在数学上,斐波纳契数列以如下被以递推的方法定义:F(1)=1,F(2)=1, F(n)=F(n-1)+F(n-2)在现代物理、准晶体结构、化学等领域,斐波纳契数列都有直接的应用,为此,美国数学会从1963年起出版了以《斐波纳契数列季刊》为名的一份数学杂志,用于专门刊载这方面的研究成果。

参考资料:

百度百科:斐波那契数列

百度百科:递归函数

求大神用Java编写出这个程序,要有具体代码,万分感激,定采纳

按照你的要求编写的JavaGUI程序如下:

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class HH extends JFrame implements ActionListener{

JPanel jp1=new JPanel();

JPanel jp2=new JPanel();

JPanel jp3=new JPanel();

JTextField jtf=new JTextField(20);

JButton jb1=new JButton("显示");

JButton jb2=new JButton("清除");

HH(){

jb1.addActionListener(this);

jb2.addActionListener(this);

jp1.setLayout(new GridLayout(2,1));

jp3.add(jtf);

jp2.add(jb1);jp2.add(jb2);

jp1.add(jp3);jp1.add(jp2);

getContentPane().add(jp1);

setSize(300, 120);

setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}

@Override

public void actionPerformed(ActionEvent e) {

if(e.getSource()==jb1){

jtf.setText("java程序设计");

}

if(e.getSource()==jb2){

jtf.setText("");

}

}

public static void main(String[] args) {

new HH();

}

}

java小程序设计求代码

Account类:

package Test;

import java.util.HashMap;

import java.util.Map;

public class Account {

private String cardId;//卡号

private String name;//姓名

private String password;//密码

private long leftAmt;//剩余金额

public MapObject, ObjectgetAccountInfo(String id){

//这里暂设一个用户信息

//实际要建一个数据库存放多个用户的信息

MapObject, Object map = new HashMapObject, Object();

map.put("cardId", "123");

map.put("name", "qwe");

map.put("password", "789");

map.put("leftAmt", 88);

//实际要通过sql语句在数据库中查询id对应的账户信息

if(id == "123"){

//这里没有考虑密码,全部返回

return map;

}

return null;

}

public void setCardId(String cardId) {

this.cardId = cardId;

}

public String getCardId() {

return cardId;

}

public void setName(String name) {

this.name = name;

}

public String getName() {

return name;

}

public void setPassword(String password) {

this.password = password;

}

public String getPassword() {

return password;

}

public void setLeftAmt(long leftAmt) {

this.leftAmt = leftAmt;

}

public long getLeftAmt() {

return leftAmt;

}

}

userOperate类:

package Test;

import java.util.HashMap;

import java.util.Map;

import java.util.Scanner;

public class UserOperate {

Account account = new Account();

public void operate(String id){

System.out.println("欢迎您使用ATM系统");

System.out.println("1--存款     2--查询");

System.out.println("3--取款    0--退出");

System.out.println("请选择操作类型【0-3】");

Scanner in = new Scanner(System.in);

int type = in.nextInt();

while(type!=0){

if(type==1){

System.out.println("请存入钞票");

type = in.nextInt();

}else

if(type==2){

System.out.println("您的银行账户信息为:");

MapObject, Object map = new HashMapObject, Object();

map = account.getAccountInfo(id);

System.out.println(map);

type = in.nextInt();

}else

if(type==3){

System.out.println("请取走您的钞票");

type = in.nextInt();

}else{

System.out.println("操作有误,请重新操作");

type = in.nextInt();

}

}

System.out.println("请尽快取走您的卡,谢谢使用!再见!");

in.close();

}

}

测试类(我放在main里):

package Test; 

public class test1 {

public static void main(String[] args){

//测试

UserOperate userOperate = new UserOperate();

//假设银行卡插入后读取到的id为123

String id = "123";

userOperate.operate(id);

}

}

运行结果:

这是很简单的一个思路,简单跑跑可以。

也不知道你要什么样的结果,如果是要一个完整的系统,那具体还得建立数据库,还有如何读取账户信息,等等。

求大神用Java编写这个程序,要有具体代码,万分感谢,定采纳

我没加注释,你有什么就直接问吧。

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

public class Cource {

private int cNumber;

private String cName;

private int cUnit;

public Cource(int cNumber, String cName, int cUnit) {

super();

this.cNumber = cNumber;

this.cName = cName;

this.cUnit = cUnit;

}

public int getcNumber() {

return cNumber;

}

public void setcNumber(int cNumber) {

this.cNumber = cNumber;

}

public String getcName() {

return cName;

}

public void setcName(String cName) {

this.cName = cName;

}

public int getcUnit() {

return cUnit;

}

public void setcUnit(int cUnit) {

this.cUnit = cUnit;

}

public void printCourceInfo(){

try {

File file=new File("out.txt");

if (!file.exists()) {

file.createNewFile();

}

BufferedWriter a=new BufferedWriter(new FileWriter(file));

a.write("课程编号,课程名,学分数");

a.newLine();

a.write(this.cNumber+","+this.cName+","+this.cUnit);

a.close();

System.out.println("输出成功");

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

import test.Cource;

public class Test {

public static void main(String[] args) {

Cource test=new Cource(121227, "课程名为Java程序设计", 3);

test.printCourceInfo();

}

}


分享名称:java程序设计示例代码,java程序设计教程例题代码
标题链接:http://cdweb.net/article/hosjed.html