资讯

精准传达 • 有效沟通

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

35个java代码的简单介绍

谁能给一个Java程序代码我,要50行到100行就可以啦。最好有几行解释

给你一个前几天才帮人写的

创新互联建站是一家专业提供桑珠孜企业网站建设,专注与网站设计、成都网站设计、H5高端网站建设、小程序制作等业务。10年已为桑珠孜众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。

“计算整钱兑零”。程序要求用户输入一个双精度数代表总元数,就会列出总值与其等价的1元币、二角五分币、5分币和1分币的数目。程序报告的数目是1元币的最大数、其次是二角五分币的最大数,等等,依此类推。只显示非零的单位。对单个单位显示单数单词,对多于一个单位的显示复数单词

import java.util.Scanner;

public class MoneyCalculate {

public static void main(String[] args) {

int max100 = 0;

int max25 = 0;

int max5 = 0;

int max1 = 0;

double money = getMoneyFromInput();

String str = String.valueOf(money).trim();

String[] ary = str.split("\\.");

max100 = Integer.parseInt(ary[0]);

if(ary.length == 2){

int fen = Integer.parseInt(ary[1]);

if(ary[1].trim().length() == 1){

fen = Integer.parseInt(ary[1]) * 10;

}

max25 = fen / 25;

if(fen % 25 != 0){

fen = fen % 25;

}else{

fen = 0;

}

max5 = fen / 5;

max1 = fen % 5;

}

StringBuilder sb = new StringBuilder(money + " = ");

if(max100 != 0){

sb.append(max100);

sb.append("*1 ");

}

if(max25 != 0){

sb.append(max25);

sb.append("*0.25 ");

}

if(max5 != 0){

sb.append(max5);

sb.append("*0.05 ");

}

if(max1 != 0){

sb.append(max1);

sb.append("*0.01 ");

}

System.out.println(sb.toString());

}

private static double getMoneyFromInput() {

Scanner scanner = new Scanner(System.in);

return scanner.nextDouble();

}

}

-----------

2.49

2.49 = 2*1 1*0.25 4*0.05 4*0.01

-----------

2.5

2.5 = 2*1 2*0.25

-----------

37.23

37.23 = 37*1 4*0.05 3*0.01

-----------------

123.569

123.569 = 123*1 22*0.25 3*0.05 4*0.01

Java斐波那契数第35个数,流程图加代码?

流程图如下:

public int Fibonacci(int n) {

  int[] res = {0, 1};

  if(n 2) {

      return res[n];

  }

  int first = 0;

  int second = 1;

  int fibn = 0;

  for(int i = 2; i = n; i++) {

      fibn = first + second;

      first = second;

      second = fibn;

  }

  return fibn;

}

public static void main(String[] args) {

System.out.println(Fibonacci(35));

}

java代码,给我写个

import javax.swing.JOptionPane;

class Rectangle extends Shape

{

public double zhouchang(double c,double k)

{

return (c + k) * 2;

}

public double mianji(double c,double k)

{

return c * k;

}

}

class Square extends Shape

{

public double zhouchang(double c,double k)

{

return (c + k) * 2;

}

public double mianji(double c,double k)

{

return c * k;

}

}

class Circle extends Shape

{

public double zhouchang(double y,double P)

{

return P * y * 2;

}

public double mianji(double y,double P)

{

return P * y * P * y;

}

}

abstract class Shape

{

public abstract double zhouchang(double x,double y);

public abstract double mianji(double x,double y);

}

public class Wb5

{

public static void main(String[] dafdasdf)

{

final double P = 3.14;

System.out.println("输入长");

double c = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Number"));

System.out.println("输入宽");

double k = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Number"));

System.out.println("输入输入半径");

double y = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Number"));

Rectangle a = new Rectangle();

double cf = a.zhouchang(c,k);

double cf1 = a.mianji(c,k);

System.out.println("长方形的周长为:"+cf);

System.out.println("长方形的面积为:"+cf1);

Square b = new Square();

double zf = b.zhouchang(c,k);

double zf1 = b.mianji(c,k);

System.out.println("正方形的周长为:"+zf);

System.out.println("正方形的面积为:"+zf1);

Circle d = new Circle();

double yy = d.zhouchang(y,P);

double yy1 = d.mianji(y,P);

System.out.println("圆形的周长为:"+yy);

System.out.println("圆形的面积为:"+yy1);

}

}

35选7 用java代码实现

public class mainClass {

public mainClass() {

}

public static void main(String []args){

int [] num = new int[35];

boolean [] flag = new boolean[35];

int count = 0;

for(int i=0;i35;i++)

{

num[i] = i + 1;

flag[i] = true;

}

while(count!=7){

int k=(int)(Math.random()*35);

if(flag[k]){

System.out.println(num[k]);

flag[k]=false;

count++;

}

}

}

}


本文标题:35个java代码的简单介绍
本文URL:http://cdkjz.cn/article/ddepded.html
多年建站经验

多一份参考,总有益处

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

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

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