java编写程序1,2或者3,4

java编写程序1,2或者3,4,第1张

public class Box 败兆{

private int c

private int k

private int g

public void setDemo(int c, int k , int g){

this.c = c

this.k = k

this.g = g

}

public void tiji(){

System.out.println("体积是: " + this.c * this.k * this.g)

}

public static void main(String[] args) {

Box b = new Box()

b.setDemo(10, 3, 4)

b.tiji()

}

}

第二题:

public class Box {

private int c

private int k

private int g

public Box(int c, int 察蠢租k, int g) {

super()

this.c = c

this.k = k

this.g = g

}

public void tiji(){

System.out.println("体积是: " + this.c * this.k * this.g)

}

public static void main(String[] 档慎args) {

Box b = new Box(5,64,2)

b.tiji()

}

}

每组的第一个数字构成斐波那契数列

所乱敬以后大皮面哗仿慎的是1 2,1 2,2 4,3 6,5 10,8 16……

代码如下:

#include<stdio.h>

void main()

{

int i,a=1,b=1

for(i=0i<20i++)

{

printf("%d",a)

printf(" ")

printf("%d",a*2)

printf(" ")

printf("%d",b)

printf(" ")

printf("%d",b*2)

printf(" ")

a=a+b

b=a+b

}

}

package com.test

import java.util.Scanner

public class Stat {

public static void main(String[] args) {

title()// 提示信息

boolean flag = true

while(flag){

Scanner scanner = new Scanner(System.in)

String var = scanner.next()

if(var.equals("1") || var.equals("2"顷御) || var.equals("3")){

if(var.equals("1")){

System.out.println("456")

}else if(var.equals("2")){

System.out.println("雀昌岩789")

}else{

System.out.println("您已经成功退出系统")

flag = false

}

}else{

System.err.println("输入错误,请按提示输入!迅竖")

title()

}

}

}

public static void title(){

System.out.println("请选择如下标识")

System.out.println("1:456")

System.out.println("2:789")

System.out.println("3:退出")

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/12569216.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存