这几个小程序用完整的JAVA语言如何编写

这几个小程序用完整的JAVA语言如何编写,第1张

3:编写一个方法统计裂行一个字符在某字符串中的吵源团出现次数; public class Test03{

public int getCounts(String s,char c){

char[] cc = s.toCharArray()

int size = cc.length

int counts = 0

for(int i=0i<sizei++){

if(cc[i]==c)counts++

}

return counts

}

public static void main(String[] args){

Test03 t = new Test03()

String s = "hello! java. I love you."

char c = 'o'

System.out.println("字符串s: "+s)

System.out.println("字符c: "+c)

System.out.println("c在s中出现的个数升橘: "+t.getCounts(s,c))

}

}

public class Test {

public static void main(String[] args) {

Trapezoid t = new Trapezoid(3, 4, 5)

System.out.println(t.area())

}

}

class Trapezoid {

private double topline

private double baseline

private double height

public Trapezoid() {

}

public Trapezoid(double topline, double baseline, double height) {

this.topline = topline

this.baseline = baseline

this.height = height

}

public double area() {

return ((topline + baseline) * height) / 2

}

}


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存