本文目录一览:
JAVA编程,玫瑰2元一支,百合3元一支,菊花5元一支,康乃馨6元一支,20元正好花完没种各多少支
public static void main(String[] args) {
for(int m = 0;m=10;m++) {//玫瑰,全买,对多买10只
for(int b = 0;b=7;b++) {//百合,全买,对多买7只
for(int j = 0;j=4;j++) {//菊花全买,对多买4只
for(int k = 0;k=4;k++) {//康乃馨全买,对多买4只
int total = 2*m+3*b+5*j+6*k;
if(20==total) {
System.out.println("玫瑰买"+m+"支,百合买"+b+"支,菊花买"+j+"支,康乃馨买"+k+"支");
}
}
}
}
}
}
java 写程序
import java.util.Scanner;
public class TestRose {
public static void main(String[] args) {
Rose r = new Rose(1000);
Scanner sc = new Scanner(System.in);
while(true) {
System.out.print("请输入送花的数量:");
try {
r.giveRose(sc.nextInt());
} catch (RoseException e) {
sc.close();
System.exit(0);
}finally {
System.out.println("我爱你!");
}
}
}
}
class Rose{
private int RoseNumber;
public int getRoseNumber() {
return RoseNumber;
}
public void setRoseNumber(int roseNumber) {
RoseNumber = roseNumber;
}
public Rose(int RoseNumber) {
this.RoseNumber = RoseNumber;
}
public void giveRose(int rose) throws RoseException{
if(roseRoseNumber) {
throw new RoseException();
}else if(rose=0){
System.out.println("方法接受到非法参数,请给出正数形式的玫瑰花数");
}else {
RoseNumber -= rose;
System.out.println("亲爱的,送你"+rose+"朵玫瑰花!");
}
}
}
class RoseException extends Exception{
private static final long serialVersionUID = 5965711409217611710L;
public RoseException() {
System.out.println("我没有钱买花送给你,对不起!");
}
}
编程题(玫瑰花数)
program roseNumber;
var
a,b,c,d:longint;
function four(n:longint):longint;
begin
four:=n*n*n*n;
end;
begin
for a:=1 to 9 do
for b:=0 to 9 do
for c:=0 to 9 do
for d:=0 to 9 do
begin
if(1000*a+100*b+10*c+d=four(a)+four(b)+four(c)+four(d))then
begin
writeln(a,b,c,d);
end
end
end.