Skip to content

Commit d5d5459

Browse files
ch09p1
1 parent f498c44 commit d5d5459

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎ch09/Test.java‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
public class Test {
2+
3+
public static void main(String[] args){
4+
String s = "Samuel"+'B'; //String + char permitted, concatenation
5+
System.out.println(s.toUpperCase());
6+
System.out.println('B'+"Samuel"); //char + String permitted, concatenation
7+
boolean vero = true;
8+
System.out.println("ZeroB"+vero); //String + boolean permitted, concatenation
9+
System.out.println(vero+"ZeroB"); //boolean + String permitted, concatenation
10+
int x = 9;
11+
System.out.println("Zero"+x); //String + int permitted, concatenation
12+
System.out.println(x+"Zero"); //int + String permitted, concatenation
13+
double c = 3.9;
14+
System.out.println("Zero"+c); //String + double permitted, concatenation
15+
System.out.println(c+"Zero"); //double + String permitted, concatenation
16+
System.out.println(x+c); //double + int and int + double permitted, double sum
17+
System.out.println('c'+x); //char + int permitted, sum of int
18+
System.out.println(x+'c'); //int + char permitted, sum of int
19+
System.out.println('c'+c); //char + double permitted, sum of double
20+
System.out.println(c+'c'); //double + char permitted, sum of double
21+
//System.out.println('c'+vero); char + boolean not legal
22+
//System.out.println(vero+'c'); boolean + char not legal
23+
//System.out.println(vero+c); boolean + double not legal
24+
//System.out.println(vero+x); boolean + int not legal
25+
//System.out.println(c+vero); int/double + bool not legal
26+
char t = 'b';
27+
//t = t + 1; Incompatible types. Found: 'int', required: 'char'
28+
System.out.println(""+5);// 5
29+
int[] histogram = letterHist("alpha");
30+
for(int occurrence: histogram){
31+
System.out.println(occurrence);
32+
}
33+
}
34+
35+
public static int[] letterHist(String s){
36+
String lows = s.toLowerCase();
37+
int[] histogram = new int[26];
38+
for(int i=0; i < lows.length(); i++){
39+
if((int)lows.charAt(i)-97<26&&(int)lows.charAt(i)-97>=0)
40+
histogram[(int)lows.charAt(i)-97]++;
41+
}
42+
return histogram;
43+
}
44+
}

0 commit comments

Comments
 (0)