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
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)