急求下列 java 程序题答案!请各位多多帮忙

急求下列 java 程序题答案!请各位多多帮忙,第1张

第一题

publci

class

Jiechen

public

staic

void

main(String[]

args){

int[]

intNum={2,4,6,10}

long

result=1

for(int

i=0,i

=50)

intGeshu++

}

Arrays.sort(intrndNum)//对数组进行从小到大排序

System.out.println(intGeshu)//打印大于50的个数

System.out.println("最小值"+intrmdNum[0])

System.out.println("最大值"+intrmdNum[99])

}

}

呵呵

我忘了最大公约数概念了,

第六题也比较简单哦

通过Switch语句进行判断,关键要对价格当成字符串处理,

public class SuperClass {

public int[] arr

public SuperClass(int[] arr){

this.arr=arr

}

public int[] getArr() {

return arr

}

public void setArr(int[] arr) {

this.arr = arr

}

public int getMax(){

int tmp=0

for(int i=0i<arr.length-1i++){

if(arr[i]>arr[i+1]){

tmp=arr[i]

arr[i]=arr[i+1]

arr[i+1]=tmp

}

}

return arr[arr.length-1]

}

}

public class SubClasses extends SuperClass{

public SubClasses(int[] arr) {

super(arr)

// TODO Auto-generated constructor stub

}

public int getMin(){

int result=0

int tmp=0

for(int i=0i<arr.length-1i++){

if(arr[i]<arr[i+1]){

tmp=arr[i]

arr[i]=arr[i+1]

arr[i+1]=tmp

}

}

return arr[arr.length-1]

}

}

public class Test {

public static void main(String[] args) {

int[] arr={4,6,1,3,2,8,9,0,5,7}

SubClasses sc=new SubClasses(arr)

int max=sc.getMax()

int min=sc.getMin()

System.out.print("max="+max)

System.out.print("min="+min)

}

}

subclass这个类名,我本地占用了,你改下。

import java.text.ParseException

import java.text.SimpleDateFormat

import java.util.Date

class Student {

private String id

private String name

private boolean isMale

private Date birth

public Student() {

super()

}

public Student(String id, String name, boolean isMale, Date birth) {

super()

this.id = id

this.name = name

this.isMale = isMale

this.birth = birth

}

public String getId() {

return id

}

public void setId(String id) {

this.id = id

}

public String getName() {

return name

}

public void setName(String name) {

this.name = name

}

public boolean isMale() {

return isMale

}

public void setMale(boolean isMale) {

this.isMale = isMale

}

public Date getBirth() {

return birth

}

public void setBirth(Date birth) {

this.birth = birth

}

@Override

public String toString() {

return "Student [id=" + id + ", name=" + name + ", isMale=" + isMale + ", birth=" + birth + "]"

}

}

public class StudentTest {

public static void main(String[] args) throws ParseException {

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd")

Student stu = new Student("00001", "Tom", true, dateFormat.parse("2000-01-01"))

System.out.println(stu)

}

}


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

原文地址: http://outofmemory.cn/yw/8073580.html

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

发表评论

登录后才能评论

评论列表(0条)

保存