Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Day13B {
- public static void main(String[] args) {
- String txtIn = "A Day Late and a Dollar Short";
- char chSearch = 'l';
- int count = 0;
- System.out.println("txtIn: " + txtIn);
- System.out.println("txtIn have " + txtIn.length() + " characters");
- System.out.println("\n-----(count with charAt())-----\n");
- for (int i = 0; i < txtIn.length(); i++) {
- if (txtIn.toLowerCase().charAt(i) == chSearch) {
- count++;
- System.out.println(txtIn.charAt(i) + "-counted");
- }
- }
- System.out.println(chSearch + "'s in the text: " + count);
- System.out.println("\n-----(finding chars and counting using charAt)-----\n");
- count = 0;
- for (int i = 0; i < txtIn.length(); i++) {
- i = txtIn.toLowerCase().indexOf(chSearch,i);
- if (i == -1) {
- i = txtIn.length();
- } else {
- System.out.println(chSearch + " is in index " + i);
- count++;
- }
- //add an if else that if i == -1 then i == txtIn.length()
- }
- System.out.println(chSearch + "'s in the text using indexOf: " + count);
- }
- }
- //----------------------------------
- class Day13C {
- public static void main(String[] args) {
- String csvText = "\"Number\",\"Team Name\",\"Member\"";
- String[] csvArray = csvText.split(",");
- for (String string : csvArray) {
- System.out.print(string + " | ");
- }
- String[] csvArray2 = {"Number,Team Name,Member"
- ,"1,Team 1,PRINCESS ANN RENDON"
- ,"2,Team 1,CARL REX ESPORSADO"
- ,"3,Team 1,REZEL MAE LOPEZ"
- ,"4,Team 1,HANNAH LYNDA BUSTILLO"
- ,"5,Team 1,JOHN PETER CATINOY"
- ,"6,Team 1,RONA FE PUYONG"
- ,"7,Team 2,RAYMOND UBALDO"
- ,"8,Team 2,JANICE ALVAREZ"
- ,"9,Team 2,IRADE PIANO"
- ,"10,Team 2,RAYMART NAPOLE"
- ,"11,Team 2,IRISH FYE SAMPOLLO"
- ,"12,Team 2,ELLEN MAE CARJASAN"
- ,"13,Team 2,VANISSA PEDRO"
- ,"14,Team 3,FLORA MAY ALAGAO"
- ,"15,Team 3,EVANGELINE SULLAGA"
- ,"16,Team 3,CLOEY MARK AMEDO"
- ,"17,Team 3,NORLIN NICOLE CABIGUNDA"
- ,"18,Team 3,JAYLYN GUZAREM"
- ,"19,Team 3,CHRISTIAN ARQUERO"
- ,"20,Team 4,JOMALYN MATANDAC"
- ,"21,Team 4,JANICE BALONGA"
- ,"22,Team 4,JEAN JUSTA SALINAS"
- ,"23,Team 4,TINA JULIA CALAUOR"
- ,"24,Team 4,ROSE ANN APOSTOL"
- ,"25,Team 4,JOHN IAN SALIDO"
- };
- for (String str : csvArray2) {
- System.out.println(str);
- }
- }
- }
- //-----------------------------------------------
- public class Day13D {
- public static void main(String[] args) {
- System.out.println("\n-----(1)-----\n");
- String txt1 = "Mississippi";
- System.out.println(txt1);
- txt1 = txt1.replace("s", "p");
- System.out.println(txt1);
- System.out.println(txt1.replace("i", "p"));
- //Mpppppppppp
- System.out.println("\n-----(2)-----\n");
- boolean change = true;
- txt1 = "A Cut Below";
- String txtResult1 = "", txtResult2 = "";
- for (char ch: txt1.toCharArray()) {
- txtResult1 += ch + "|";
- if (ch != ' ') {
- if (change) {
- txtResult2 += String.valueOf(ch).toUpperCase() + "_";
- change = false;
- } else {
- txtResult2 += String.valueOf(ch).toLowerCase()+ "_";
- change = true;
- }
- } else {
- txtResult2 += ch + "_";
- }
- }
- System.out.println("1: " + txtResult1 );
- System.out.println("2: " + txtResult2 );
- System.out.println("\n-----(3)-----\n");
- txt1 = "Sandwiches";
- System.out.println(txt1);
- System.out.println(txt1.substring(4));
- System.out.println(txt1.substring(0, 4));
- System.out.println("\n-----(4)-----\n");
- int startNum = 0;
- int endNum = 0;
- boolean isPrevSpace = true;
- txt1 = " As above so below";
- System.out.println(txt1);
- System.out.println("trimmed: " + txt1.trim());
- for (int i = 0; i < txt1.length(); i++) {
- if (txt1.charAt(i) != ' ' && isPrevSpace) {
- startNum = i;
- isPrevSpace = false;
- System.out.println("s:"+startNum);
- } else if (txt1.charAt(i) == ' ' && !isPrevSpace) {
- endNum = i;
- isPrevSpace = true;
- System.out.println("e:"+endNum);
- System.out.println("|"+txt1.substring(startNum, endNum)+"|");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment