导航:首页 > 编程语言 > java编程作业

java编程作业

发布时间:2023-01-24 14:23:52

『壹』 java编程作业,求打救,急.............................

import java.util.Random;

public class StudentsAward {

public static void main(String[] args) {
int[] id = {1,2,3,4,5,6,7,8,9,10};
boolean[] used = new boolean[id.length];
Random r = new Random();
int i ,j=0;
do{
i = r.nextInt(id.length);
if(used[i]){
continue;
}
j++;
System.out.println("三等奖获得者是:"+id[i]+"号");
used[i] =true;
}while(j!=3);
do{
i = r.nextInt(id.length);
if(used[i]){
continue;
}
j++;
System.out.println("二等奖获得者是:"+id[i]+"号");
used[i] =true;
}while(j!=5);
do{
i = r.nextInt(id.length);
if(used[i]){
continue;
}
j++;
System.out.println("一等奖获得者是:"+id[i]+"号");
used[i] =true;
}while(j!=6);
}
}

『贰』 java编程作业

public class Customer {
private String memberName;
private int memberNo;

public Customer(String memberName,int memberNo){
this.memberName = memberName;
this.memberNo = memberNo;
}

public String getMemberName() {
return memberName;
}
public void setMemberName(String memberName) {
this.memberName = memberName;
}
public int getMemberNo() {
return memberNo;
}
public void setMemberNo(int memberNo) {
this.memberNo = memberNo;
}
}
----------------------------------分界线---------------------------------------------------

import java.util.ArrayList;

public class CustManager {
private static ArrayList<Customer> list = new ArrayList<Customer>();

public void addCust(String memberName,int memberNo){
list.add(new Customer(memberName, memberNo));
}

public int searchMemberByName(String memberName){
if(memberName == null || memberName.equals("")){
return 1;
}
for(Customer c : list){
if(memberName.equals(c.getMemberName())){
return c.getMemberNo();
}
}
return 0;
}
}
----------------------------------分界线---------------------------------------------------

public class Test {
public static void main(String[] args) {
CustManager custManager = new CustManager();
custManager.addCust("张三", 1);
custManager.addCust("李四", 2);
custManager.addCust("王五", 3);
custManager.addCust("马六", 4);

System.out.println(custManager.searchMemberByName("马六"));
}
}

『叁』 java编程的作业试题大家帮我解答一下,谢谢了,一共两个题,在下面,请大家一定要帮我解答一下,我不会做

仅供参考,未测试

Question1

packagecom.kidd.atmtest;

importjava.util.Scanner;

publicclassQuestion1{
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner(System.in);
System.out.print("输入基本运费,货重,距离(均为整数,用,分割):");
String[]ss=scanner.next().split(",");
intp=Integer.parseInt(ss[0]);
intw=Integer.parseInt(ss[1]);
ints=Integer.parseInt(ss[2]);

doubled;
if(s<250){
d=0;
}elseif(s<500){
d=0.02;
}elseif(s<1000){
d=0.05;
}elseif(s<2000){
d=0.08;
}else{
d=0.1;
}

System.out.println("总运费f="+(p*w*s*(1-d)));
}
}

Question2

packagecom.kidd.atmtest;

importjava.util.Scanner;

publicclassQuestion2{
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner(System.in);
System.out.print("请输入x:");
intx=scanner.nextInt();
inty;
if(x<0){
y=-1;
}elseif(x>0){
y=1;
}else{
y=0;
}
System.out.println("y="+y);
}
}

Question3

packagecom.kidd.atmtest;

importjava.util.Scanner;

publicclassQuestion3{
publicstaticvoidmain(String[]args){
intindex=0;

Scannerscanner=newScanner(System.in);
booleanend=false;
while(!end){
System.out.print("请输入卡号,密码:");
scanner.next();
index++;

System.out.print("账号或密码错误次数"+index+",");
if(index>=3){
System.out.println("吞卡");
end=true;
}else{
System.out.println("请重新输入.");
}

}

}
}

Question4

packagecom.kidd.atmtest;

importjava.util.Scanner;

publicclassQuestion4{
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner(System.in);
System.out.print("输入一个整数:");

Stringstring=scanner.next();
for(inti=0,k=string.length();i<k;i++){
System.out.println(string.charAt(i));
}

}
}

Question5

packagecom.kidd.atmtest;

importjava.util.Random;
importjava.util.Scanner;

publicclassQuestion5{
publicstaticvoidmain(String[]args){
inti=newRandom().nextInt(40)+60;

booleanend=false;
intn;
intindex=1;
Scannerscanner=newScanner(System.in);
while(!end){
System.out.print("请输入你猜的结果:");
n=scanner.nextInt();
if(n>i){
System.out.println("大了");
index++;
}elseif(n<i){
System.out.println("小了");
index++;
}else{
end=true;
}
}

System.out.print("猜对了,一共猜了"+index+"次,你是");
if(index<5){
System.out.print("天才.");
}else{
System.out.print("笨蛋.");
}

}
}

Question6

packagecom.kidd.atmtest;

importjava.util.Scanner;

publicclassQuestion6{
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner(System.in);
System.out.print("请输入要打印的元素个数:");

intn=scanner.nextInt();

if(n<1){
System.out.println("无输出结果");
}
if(n>=1){
System.out.print("1");
}
if(n>=2){
System.out.print(",2");
}

if(n>2){
intf1=1;
intf2=2;
intsum;

for(inti=3;i<=n;i++){
sum=f1+f2;
System.out.print(","+(f1+f2));
f1=f2;
f2=sum;
}

}
}
}

『肆』 Java编程作业

public static void main(String[] args) {
System.out.println("请输入内容:");
while (true) {
Scanner s = new Scanner(System.in);
String str = s.next();//原始字符串
if(str.equals("!")){
//System.out.println("请重新输入内容:");//继续用这个
break;//退出用这个

}else{

String afterAtr="";//修改后
int num = 0;//修改数量
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (Character.isLowerCase(c)) {
afterAtr += Character.toUpperCase(c);
num++;
}else if (Character.isUpperCase(c)) {
afterAtr += Character.toLowerCase(c);
num++;
}else{
afterAtr += c;
}
}
System.out.println("原始内容:"+str+";修改后内容:"+afterAtr+";修改数量:"+num);
}

}
}

『伍』 JAVA编程作业

importjava.math.BigDecimal;
importjava.util.Random;

publicclassIncrease{

publicstaticbooleanisPrime(inta){

booleanflag=true;

if(a<2){//素数不小于2
returnfalse;
}else{

for(inti=2;i<=Math.sqrt(a);i++){

if(a%i==0){//若能被整除,则说明不是素数,返回false

flag=false;
break;//跳出循环
}
}
}
returnflag;
}

publicstaticvoidtest1(){
inti,n,k=0;
System.out.println("1-1000内素数");
for(n=3;n<=1000;n++){//3~1000的所有数
i=2;
while(i<n){
if(n%i==0)break;//若能整除说明n不是素数,跳出当前循环
i++;
}


if(i==n){//如果i==n则说明n不能被2~n-1整除,是素数
k++;//统计输出数的个数
System.out.print(i+" ");
if(k%6==0)//每输出5个则换行
System.out.println();
}
}
}
publicstaticvoidtest2()
{
Randomr=newRandom();
System.out.println(r.nextInt(301)-100);
}
publicstaticinttest3(intm,intn){
//辗转相除法
intr;
do{
if(m<n)
{
r=m;
m=n;
n=r;
}
r=m%n;
m=n;
n=r;
}while(r!=0);
returnm;
}
publicstaticdoubletest4(intn){
doublee=1f;
doubletotal=1.0;
for(inti=0;i<n;i++)
{
total/=i+1;
e+=total;
}
BigDecimalb=newBigDecimal(e);
e=b.setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue();//表明四舍五入,保留四位小数
returne;
}
publicstaticvoidmain(String[]args){
//第一题测试
System.out.println(isPrime(131));
test1();
//第二题测试
test2();
//第三题测试
System.out.println("最大公约数为:"+test3(1302,19924));
//第四题测试
System.out.println("e="+test4(100));
}
}

运行结果:

true

1-1000内素数

3 5 7 11 13 17

19 23 29 31 37 41

43 47 53 59 61 67

71 73 79 83 89 97

101 103 107 109 113 127

131 137 139 149 151 157

163 167 173 179 181 191

193 197 199 211 223 227

229 233 239 241 251 257

263 269 271 277 281 283

293 307 311 313 317 331

337 347 349 353 359 367

373 379 383 389 397 401

409 419 421 431 433 439

443 449 457 461 463 467

479 487 491 499 503 509

521 523 541 547 557 563

569 571 577 587 593 599

601 607 613 617 619 631

641 643 647 653 659 661

673 677 683 691 701 709

719 727 733 739 743 751

757 761 769 773 787 797

809 811 821 823 827 829

839 853 857 859 863 877

881 883 887 907 911 919

929 937 941 947 953 967

971 977 983 991 997 106

最大公约数为:2

e=2.7183

『陆』 java编程作业:构造方法的重载

我是初学者,我把我写的给你看看,我们可以一起学习交流的啊~

class Point{
double x,y;
Point(double x,double y){
this.x = x;
this.y = y;
}
double getX(){
return x;
}
double getY(){
return y;
}
}
class Circle{
double r;
Point pp;
Circle(double r){
this.r = r;
pp =new Point (0,0);
}
Circle(double r,Point p ){
this.r = r;
this.pp=p;
}
boolean isContain(Point pt){
double a =(pp.x-pt.x)*(pp.x-pt.x)+(pp.y-pt.y)*(pp.y-pt.y);
double b = this.r*this.r;
if(a<b){
return true;
}else{
return false;
}
}
}
public class TestOverLoad{
public static void main (String[] args){
Circle c1=new Circle(1);
Point p=new Point(1,1);
System.out.println(c1.isContain(p));
}
}

『柒』 Java编程作业,急用

以下是源代码和运行结果截图,如果哪里有问题的话可以来找我。

classPet{

intage;

intweight;

publicPet(intage,intweight){

super();

this.age=age;

this.weight=weight;

}

publicvoidshowInfo(){

System.out.println("myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnthis.weight;

}

publicintgetAgeInfo(){

returnthis.age;

}

}

interfaceEatable{

publicabstractvoidbeEatted();//默认为public和abstract

}

classCatextendsPet{

publicCat(intage,intweight){

super(age,weight);

//TODOAuto-generatedconstructorstub

}

privateintcry;

publicvoidshowInfo(){

System.out.println("I'maCat,myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnsuper.getWeightInfo();

}

publicintgetAgeInfo(){

returnsuper.getAgeInfo();

}

}

{

publicDog(intage,intweight){

super(age,weight);

//TODOAuto-generatedconstructorstub

}

privateintcry;

publicvoidshowInfo(){

System.out.println("I'maDog,myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnsuper.getWeightInfo();

}

publicintgetAgeInfo(){

returnsuper.getAgeInfo();

}

publicvoidbeEatted(){

}

}

classFruitimplementsEatable{

publicFruit(Stringcolor,Stringaddress){

super();

this.color=color;

this.address=address;

}

Stringcolor;

Stringaddress;

publicvoidbeEatted(){

System.out.println("I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("mycoloris"+this.color+"andmyaddressis"+this.address);

}

publicStringgetColorInfo(){

returnthis.color;

}

publicStringgetAddressInfo(){

returnthis.address;

}

}

classBananaextendsFruit{

publicBanana(Stringcolor,Stringaddress){

super(color,address);

//TODOAuto-generatedconstructorstub

}

publicvoidbeEatted(){

System.out.println("I'maBanana,I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("I'maBanana,mycoloris"+this.color+"andmyaddressis"+this.address);

}

@Override

publicStringgetColorInfo(){

//TODOAuto-generatedmethodstub

returnthis.getColorInfo();

}

@Override

publicStringgetAddressInfo(){

returnthis.getAddressInfo();

}

}

classAppleextendsFruit{

Stringtype;

publicApple(Stringcolor,Stringaddress,Stringtype){

super(color,address);

this.type=type;

//TODOAuto-generatedconstructorstub

}

publicStringgetType(){

returntype;

}

publicvoidbeEatted(){

System.out.println("I'manapple,I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("I'manApple,mycoloris"+this.color+",myaddressis"+this.address

+"andmytypeis"+type);

}

@Override

publicStringgetColorInfo(){

//TODOAuto-generatedmethodstub

returnthis.getColorInfo();

}

@Override

publicStringgetAddressInfo(){

returnthis.getAddressInfo();

}

}

publicclassPrograms{

publicstaticvoidmain(String[]args){

Catmycat=newCat(10,20);

Dogmydog=newDog(10,24);

Bananamybanana=newBanana("黄色","北京");

Applemyapple=newApple("红色","上海","新品种");

mycat.showInfo();

mydog.showInfo();

mybanana.showInfo();

myapple.showInfo();

mydog.beEatted();

mybanana.beEatted();

myapple.beEatted();

}

}

阅读全文

与java编程作业相关的资料

热点内容
qq旋风文件名 浏览:270
手机system文件 浏览:672
我的网络被房东禁了 浏览:505
c获取配置文件 浏览:476
苹果5s5gwifi 浏览:261
棋类程序编程一般用什么算法 浏览:792
dnf86版本红字 浏览:452
xp去掉域登陆密码 浏览:729
淘宝全屏显示代码 浏览:921
大数据内涵体现在下列哪个方面 浏览:105
数据网络怎么自己打开了 浏览:688
可编程控制器的优点有哪些 浏览:623
g502配置文件 浏览:159
1024b数据多少字节 浏览:720
java俄罗斯方块设计说明书 浏览:313
英雄联盟710版本锐雯 浏览:818
keil编译后显示代码大小 浏览:959
一份多页纸质文件转换成pdf 浏览:43
论文数据很少怎么办 浏览:972
哪个app可以卖二手课程 浏览:474

友情链接