Comments (26)
package day8task01;
import javax.swing.JOptionPane;
/**
*
-
@author DELL
*/
public class Day8task01 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String s1;
String s2;
int choice;
choice = Integer.parseInt(JOptionPane.showInputDialog("1:concatination\n2:comparison\n3:upper/lowercase\n4:charAt(index)\n5:substring\n6:replace\n7:indexcheck\n8:trim\n\nYour choice????"));
switch (choice) {
case 1:
s1 = JOptionPane.showInputDialog("enter first string");
s2 = JOptionPane.showInputDialog("enter second string");
JOptionPane.showMessageDialog(null, s1.concat(s2), "concatinated string", 1);
break;case 2: s1 = JOptionPane.showInputDialog("enter first string"); s2 = JOptionPane.showInputDialog("enter second string"); if (s1.equals(s2)) { JOptionPane.showMessageDialog(null, "equal", "comparison", 1); } if (s1.equalsIgnoreCase(s2)) { JOptionPane.showMessageDialog(null, "not equal", "comparison", 1); } break; case 3: s1 = JOptionPane.showInputDialog("enter the string"); JOptionPane.showMessageDialog(null, s1.toUpperCase(), " ", 1); JOptionPane.showMessageDialog(null, s1.toLowerCase(), " ", 1); break; case 4: s1 = JOptionPane.showInputDialog("enter the string"); for (int i = 0; i < s1.length(); i++) { JOptionPane.showMessageDialog(null, s1.charAt(i), " ", 1); } break; case 5: s1 = JOptionPane.showInputDialog("enter the string"); JOptionPane.showMessageDialog(null, s1.substring(0, 2), " ", 1); JOptionPane.showMessageDialog(null, s1.substring(3, 4), " ", 1); JOptionPane.showMessageDialog(null, s1.substring(4, 6), " ", 1); break; case 6: s1 = JOptionPane.showInputDialog("enter the string"); JOptionPane.showMessageDialog(null, s1.replace("a", "A"), "", 1); break; case 7: s1 = JOptionPane.showInputDialog("enter the string"); JOptionPane.showMessageDialog(null, s1.indexOf('a'), "Index of a", 1); break; case 8: s1 = JOptionPane.showInputDialog("enter the string"); JOptionPane.showMessageDialog(null, s1.trim(), "Trimmed", 1); break; default: JOptionPane.showMessageDialog(null, "You should enter valid choice", "Error", 2);
}
}
-
from java.
package day8a1;
import static java.lang.Integer.parseInt;
import javax.swing.JOptionPane;
/**
*
-
@author User
*/
public class Day8A1 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {int ch;
String s1, s2;
JOptionPane.showMessageDialog(null,"1.Concatination\n2.Comparison\n3.toUpperCase/toLowerCase\n4.chatAt(index)\n5.Substring\n6.Replace\n7.indexOf(char)\n8.trim()", "Enter your choice", 3);
ch = parseInt(JOptionPane.showInputDialog("Enter your choice"));
switch (ch) {
case 1:
s1 = JOptionPane.showInputDialog("Enter first string!");
s2 = JOptionPane.showInputDialog("Enter second string!");
JOptionPane.showMessageDialog(null, s1.concat(s2), "After Concatination", 1);
break;
case 2:
s1 = JOptionPane.showInputDialog("Enter first string!");
s2 = JOptionPane.showInputDialog("Enter second string!");
if (s1.equals(s2)) {
JOptionPane.showMessageDialog(null, "Both String are same", "After Comparing", 1);
} else {
JOptionPane.showMessageDialog(null, "Both String are not same", "After Comparing", 1);
}
break;
case 3:
s1 = JOptionPane.showInputDialog("Enter a string!");
JOptionPane.showMessageDialog(null, s1.toUpperCase(), "Uppercase of" + s1, 1);
JOptionPane.showMessageDialog(null, s1.toLowerCase(), "Lowercase of" + s1, 1);
break;
case 4:
s1 = JOptionPane.showInputDialog("Enter a string!");
for (int i = 0; i < s1.length(); i++) {
JOptionPane.showMessageDialog(null, s1.charAt(i), "Displaying" + s1, 1);
}
break;
case 5:
s1 = JOptionPane.showInputDialog("Enter a string");
int l = s1.length();
JOptionPane.showMessageDialog(null, s1.substring(0, 1), "Displaying first element ", 1);
JOptionPane.showMessageDialog(null, s1.substring(l - 1, l), "Displaying last element ", 1);
break;
case 6:
s1 = JOptionPane.showInputDialog("Enter your CRN");
int len = s1.length();
if (len < 6 || len > 6) {
s1 = JOptionPane.showInputDialog("Enter a valid CRN");
}
String a = s1.replace(s1.substring(0, 2), "Batch" + 20 + s1.substring(0, 2) + "");
JOptionPane.showMessageDialog(null, a);
String b = s1.replace(s1.substring(3, 4), "Department" + s1.substring(3, 4) + "");
JOptionPane.showMessageDialog(null, b);
String c = s1.replace(s1.substring(4, 6), "Roll No" + s1.substring(4, 6) + "_");
JOptionPane.showMessageDialog(null, c);
break;
case 7:
s1 = JOptionPane.showInputDialog("Enter a string!");
s2 = JOptionPane.showInputDialog("Enter string to be indexed");
JOptionPane.showMessageDialog(null, s1.indexOf(s2));
break;
case 8:
s1 = JOptionPane.showInputDialog("Enter a string!");
JOptionPane.showMessageDialog(null, s1.trim());
break;
default:
JOptionPane.showMessageDialog(null, "Invalid Choice");
break;
}
}
-
}
O/P:
Enter your choice:
Choice 1:
Choice 2:
Choice 3:
Choice 4:
Choice 5:
Choice 6:
Choice 7:
Choice 8:
from java.
Program
package stringopercase;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
import java.util.regex.Pattern;
/**
*
-
@author m-lan
*/
public class StringOperCase {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
int sn;
String crn, s, s1, s2, n1, n2, dpt, dpt_name, np;
Scanner input = new Scanner(System.in);
System.out.println("Here are the Choices.Enter number to choose");
System.out.println("1.Concatenation");
System.out.println("2.Comparison");
System.out.println("3.toUpperCase, toLowerCase");
System.out.println("4.charAt(index)");
System.out.println("5.Substring");
System.out.println("6.Replace");
System.out.println("7.indexOf(char)");
System.out.println("8.trim()");System.out.printf("=>");
sn = input.nextInt();
switch (sn) {
case 1:
System.out.println("Enter first String:");
s1 = input.next();
System.out.println("Enter Second String:");
s2 = input.next();
System.out.println("String1=" + s1 + " " + "String2=" + s2);
System.out.println("After Concatenating...");
System.out.println(s1 + s2);
System.out.println(s1.concat(s2));
System.out.println(s1.concat(s2.concat(s1)));
break;case 2: System.out.println("Enter first String:"); n1 = input.next(); System.out.println("Enter Second String:"); n2 = input.next(); System.out.println("String1=" + n1 + " " + "String2=" + n2); System.out.println("After Comparing..."); if (n1.equals(n2)) { System.out.println("Given string Are same"); } else{ System.out.println("Given string Are Different"); } if (n1.equalsIgnoreCase(n2)) { System.out.println("Given string Are same without considering Case"); } else{ System.out.println("Given string Are Different without considering Case"); } break; case 3: System.out.println("Enter first String:"); s1 = input.next(); System.out.println("Enter Second String:"); s2 = input.next(); System.out.println("String1=" + s1 + " " + "String2=" + s2); System.out.println("After Changing to Upper and Lower Case and Capitalize..."); System.out.println(s1.toUpperCase()); System.out.println(s1.toLowerCase()); System.out.println(StringUtils.capitalize(s1.toLowerCase())); break; case 4: System.out.println("Enter first String:"); n1 = input.next(); System.out.println("String=" + n1); System.out.println("Separating letter using charAt()..."); for (int i = 0; i < n1.length(); i++) { System.out.println(n1.charAt(i)); } break; case 5: System.out.println("Enter College Roll No.:"); crn = input.next(); if (Pattern.matches("[a-zA-Z]+", crn) == true || crn.length() > 6) { System.out.println("Invalid College Roll Number"); } else { dpt = crn.substring(2, 4); if (dpt.equals("01")) { dpt_name = "Civil Engineering"; } else if (dpt.equals("02")) { dpt_name = "Architecture"; } else if (dpt.equals("03")) { dpt_name = "Computer Engineering"; } else if (dpt.equals("04")) { dpt_name = "Electronics Engineering"; } else { dpt_name = "Unknown"; } System.out.println("Batch:20" + crn.substring(0, 2)); System.out.println("Department:" + dpt_name); System.out.println("Rollno.:" + crn.substring(4, 6)); } break; case 6: System.out.println("Enter College Roll No.:"); crn = input.next(); if (Pattern.matches("[a-zA-Z]+", crn) == true || crn.length() > 6) { System.out.println("Invalid College Roll Number"); } else { System.out.println("Rollno as a whole is " + crn); System.out.println("After Replacing..."); String hh = crn.replace("71", "Batch 2071 "); System.out.println(hh.replace("03", "Computer ")); } break; case 7: System.out.println("Enter String:"); s = input.next(); System.out.println("String is " + s); System.out.println("IndexOf"); System.out.println("M=" + s.indexOf('M')); System.out.println("L=" + s.indexOf('L')); System.out.println("Last index of N=" + s.lastIndexOf('N')); break; case 8: System.out.println("Enter String with space like ( Nepal ):"); np = input.next(); System.out.println("String with space is " + np); System.out.println("Without Trim = " + np); System.out.println("With Trim = " + np.trim()); break; default: System.out.println("Invalid Choice");
}
}
-
}
from java.
@milan604 Try to read required string from console too.
from java.
package stringoptions;
import java.util.Scanner;
/**
*
-
@author Jagdish Duwal
*/
public class StringOptions {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {String s,s1,s2 ;
int i,j;
String redo;
Scanner input = new Scanner(System.in);
do{
System.out.println("Read the following menu"); System.out.println("1. Concatenation \n2.comparison \n3. toUpperCase \n4.toLowerCase \n5.CharacterAt(index) \n6.Substring(index1, index2) \n7.Replace \n8.indexOf(char) \n9.lastIndexOf(char) \n10.trim "); System.out.println("Enter your choice"); int choice; choice = input.nextInt(); switch(choice){ case 1: System.out.println("Enter two strings to concatinate"); System.out.println("1st string: "); s1 = input.next(); System.out.println("2nd string: "); s2 = input.next(); System.out.println("the concatinated string is "+ s1.concat(s2)); break; case 2: System.out.println("Enter two strings to compare"); System.out.println("1st string: "); s1 = input.next(); System.out.println("2nd string: "); s2 = input.next(); if(s1.equals(s2)) System.out.println("the strings are same"); else if(s1.equalsIgnoreCase(s2)) System.out.println("the strings are same ignoring the case"); else System.out.println("the strings are not same"); break; case 3: System.out.println("Enter a string to change into upper case"); s1 = input.next(); System.out.println("the string in upper case is : " + s1.toUpperCase()); break; case 4: System.out.println("Enter a string to change into lower case"); s1 = input.next(); System.out.println("the string in lower case is : " + s1.toLowerCase()); break; case 5: System.out.println("Enter a string"); s1 = input.next(); System.out.println("Enter a index to find the character at"); i = input.nextInt(); System.out.println("the char at the given index is: "+ s1.charAt(i)); break; case 6: System.out.println("Enter a string"); s1 = input.next(); System.out.println("Enter a starting index"); i = input.nextInt(); System.out.println("Enter a ending "); j = input.nextInt(); System.out.println("Using Substring operation "+ s1.substring(i, j)); break; case 7: System.out.println("Enter a string"); s = input.next(); System.out.println("Enter the string you want to replace in string1"); s1 = input.next(); System.out.println("What do u want to replace it with? "); s2 = input.next(); System.out.println("After replacing we get, "+ s.replace(s1,s2)); break; case 8: System.out.println("Enter a string"); s = input.next(); System.out.println("Enter a character"); s1 = input.next(); System.out.println("the index of the character is: " + s.indexOf(s1.charAt(0))); break; case 9: System.out.println("Enter a string"); s = input.next(); System.out.println("Enter a character"); s1 = input.next(); System.out.println("the last index of the character is: " + s.lastIndexOf(s1.charAt(0))); break; case 10: System.out.println("Enter a string with spaces"); s = input.next(); System.out.println("String after trim: "+ s.trim()); break; default: System.out.println("Invalid Entry. Please read the menu carefully"); } System.out.println("Do you want to try again?(press y if yes)"); redo = input.next();
}while(redo.equalsIgnoreCase("y"));
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package day09task;
import java.util.Scanner;
/**
*
-
@author Dragon15423
*/
public class Day09Task {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner n = new Scanner(System.in);
Scanner ne = new Scanner(System.in);
System.out.println("String Operations:");System.out.print("Enter the 1st string: ");
String s1 = ne.nextLine();
System.out.print("Enter the 2nd string: ");
String s2 = ne.nextLine();
System.out.println("1)Concatenation\n2)Comparision\n3)toUpperCase or toLowerCase\n4)charAt(index)\n5)Substring\n6)Replace\n7)indexOf(char) and lastIndexOf(char)\n8)trim()");
System.out.println("Enter your choice: ");
int number = n.nextInt();
switch (number) {case 1: System.out.println(s1 + s2); System.out.println(s1.concat(s2)); System.out.println(s1.concat(s1.concat(s2))); break; case 2: if (s1.equals(s2)) { System.out.println("Strings are same"); } else { System.out.println("They are different"); } if (s1.equalsIgnoreCase(s2)) { System.out.println("Strings are same"); } else { System.out.println("They are different"); } break; case 3: System.out.println(s1.toUpperCase() + s2.toLowerCase()); System.out.println(s1.toLowerCase() + s2.toUpperCase()); break; case 4: for (int i = 0; i < s1.length(); i++) { char cha = s1.charAt(i); System.out.println(cha); } break; case 5: System.out.println(s1.substring(0, 2)); System.out.println(s1.substring(3, 4)); System.out.println(s2.substring(0, 5)); break; case 6: System.out.println("Enter a roll no. = "); String roll = ne.nextLine(); System.out.println("Your Roll no =" + roll); if (roll.length() == 6) { System.out.println("Batch 20" + roll.substring(0, 2)); String com = roll.substring(2, 4); switch (com) { case "01": System.out.println("Civil Department"); break; case "02": System.out.println("Architecture Department"); break; case "03": System.out.println("Computer Department"); break; case "04": System.out.println("Electronics Department"); break; default: System.out.println("not valid"); break; } } else { System.out.println("not valid roll number"); } break; case 7: System.out.println("Position of s =" + s1.indexOf('s')); System.out.println("Position of n =" + s1.lastIndexOf("n")); break; case 8: System.out.println("Enter a string with some spaces in the front:"); String s3 = ne.nextLine(); System.out.println("before trim = " + s3); System.out.println("after trim = " + s3.trim()); break; default: System.out.println("not valid number");
-
from java.
package day8a1;
import java.util.Scanner;
/**
*
-
@author Albina Praz
*/
public class Day8A1 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic hereScanner input = new Scanner(System.in);
Scanner a = new Scanner(System.in);
Scanner b = new Scanner(System.in);
String redo;
System.out.println("String Operations:");
System.out.print("Enter the 1st string: ");String s1 = a.nextLine();
System.out.print("Enter 2nd string: ");
String s2 = b.nextLine();
System.out.print("Enter 3rd string");
String s3 = a.nextLine();do {
System.out.println("Enter the Choices");
System.out.println("1.Concatenation");
System.out.println("2.Comparison");
System.out.println("3.toUpperCase, toLowerCase");
System.out.println("4.charAt(index)");
System.out.println("5.Substring");
System.out.println("6.Replace");
System.out.println("7.indexOf(char)");
System.out.println("8.trim()");
System.out.println("Enter your choice: ");
int number = a.nextInt();
switch (number) {
case 1:
System.out.println("String1=" + s1 + " " + "String2=" + s2);
System.out.println("After Concatenating...");
System.out.println(s1 + s2);
System.out.println(s1.concat(s2));
System.out.println(s1.concat(s2.concat(s3)));
break;case 2: if (s1.equals(s2)) { System.out.println("Strings are same"); } else { System.out.println("They are different"); } if (s1.equalsIgnoreCase(s2)) { System.out.println("Strings are same"); } else { System.out.println("They are different"); } break; case 3: System.out.println(s1.toUpperCase() + s2.toLowerCase()); System.out.println(s1.toLowerCase() + s2.toUpperCase()); break; case 4: for (int i = 0; i < s1.length(); i++) { char c = s1.charAt(i); System.out.println(c); } break; case 5: System.out.println(s1.substring(0, 2)); System.out.println(s1.substring(3, 4)); System.out.println(s2.substring(4, 6)); break; case 6: System.out.println("Enter a roll no. = "); String roll = b.nextLine(); System.out.println("Your Roll no =" + roll); if (roll.length() == 6) { System.out.println("Batch 20" + roll.substring(0, 2)); String com = roll.substring(2, 4); switch (com) { case "01": System.out.println("Civil Department"); break; case "02": System.out.println("Architecture Department"); break; case "03": System.out.println("Computer Department"); break; case "04": System.out.println("Electronics Department"); break; default: System.out.println("not valid"); break; } } else { System.out.println("not valid roll number"); } break; case 7: System.out.println("Position of s =" + s1.indexOf('s')); System.out.println("Position of n =" + s1.lastIndexOf("n")); break; case 8: System.out.println("Enter a string with some spaces in the front:"); String s4 = b.nextLine(); System.out.println("before trim = " + s4); System.out.println("after trim = " + s4.trim()); break; default: System.out.println("not valid number"); } System.out.println("Do you want to try again?(press y if yes)"); redo = input.next();
} while (redo.equalsIgnoreCase("y"));
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package stgoperate;
import java.util.Scanner;
/**
*
-
@author LORDsajan
*/
public class StgOperate {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Strings operations");
Scanner inp = new Scanner(System.in);
String cont;
System.out.println("enter what operation you want\n1>Concatenation\n2>Comparision\n3>toUppercase or toLowercase\n4>charAt(index)\n5>Substring\n6>Replace\n7>IndexOf(char)\n8>trim()");do {
System.out.print("choice=");
int choice = inp.nextInt();
switch (choice) {
case 1:
System.out.println("enter two strings to concatinate");
String s1 = inp.next();
String s2 = inp.next();
System.out.println("After concatination");
System.out.println(s1.concat(s2));
break;
case 2:
System.out.println("enter two strings to compare");
String s3 = inp.next();
String s4 = inp.next();
if (s3.equalsIgnoreCase(s4)) {
System.out.println("Its matches");
} else {
System.out.println("doesnt match1");
}
break;
case 3:
System.out.println("enter a string");
String s5 = inp.next();
System.out.println("after changing to upper case");
System.out.println(s5.toUpperCase());
System.out.println("after changing to lower case");
System.out.println(s5.toLowerCase());
break;
case 4:
System.out.println("enter a string");
String s6 = inp.next();
System.out.println("After seperating string into characters");
for (int i = 0; i < s6.length(); i++) {
System.out.println(s6.charAt(i));
}
break;case 5: String test1; do { System.out.println("enter a string"); String s7 = inp.next(); System.out.println("enter the value for substring "); int a = inp.nextInt(); int b = inp.nextInt(); if (a > s7.length() && b > s7.length()) { System.out.println("invalid value"); test1 = "false"; } else { System.out.println("The sustring is"); System.out.println(s7.substring(a, b)); test1 = "true"; } } while (test1.equals("false")); break; case 6: String test2; do { System.out.println("enter College roll number"); String s8 = inp.next(); String s9 = s8.substring(0, 2); String s10 = s8.substring(3, 4); String s11 = s8.substring(4, 6); if (s8.length() == 6) { System.out.println(s8.replace(s9, "-Batch 20" + s9 + "-")); System.out.println(s8.replace(s10, "-Computer-")); System.out.println(s8.replace(s11, "-rollNo-")); test2 = "true"; } else { System.out.println("Invalid input"); test2 = "false"; } } while (test2.equals("false")); break; case 7: System.out.println("enter a string"); String s12 = inp.next(); System.out.println("enter the character or string to find its index"); String s13 = inp.next(); System.out.println(s12.indexOf(s13)); break; case 8: System.out.println("enter a string"); String s14 = inp.next(); System.out.println("after trimmimg"); System.out.println(s14.trim()); break; default: System.out.println("Invalid choice"); break; } System.out.println("Contine again?"); cont = inp.next();
} while (cont.equalsIgnoreCase("y"));
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package stringoperationfromuser;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author dell
*/
public class StringOPerationFromUser {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {// TODO code application logic here
String t1, t2, t, crn;
int c;
String check = "y";
Scanner text = new Scanner(System.in);
while (check.equalsIgnoreCase("y")) {
System.out.println("enter your choice");
System.out.println("1-string Concatinate\n2-string compare\n3- Touppercase\n4-CharAt\n5-substring\n6-Replace\n7-indexofChar\n8-trim");
Scanner choice = new Scanner(System.in);
c = choice.nextInt();
switch (c) {
case 1: {
System.out.println("enter your first text for concatenation");
t1 = text.next();
System.out.println("enter your second text for concatenation");
t2 = text.next();
System.out.println(t1.concat(t2));
}
break;
case 2:
System.out.println("enter your first text for comparision");
t1 = text.next();
System.out.println("enter your second text for comparision");
t2 = text.next();if (t1.equals(t2)) { System.out.println("same text"); } else { System.out.println("different text"); } break; case 3: System.out.println("enter your text to change into lower case "); t1 = text.next(); System.out.println(t1.toLowerCase()); System.out.println("enter your text to change into upper case "); t2 = text.next(); System.out.println(t2.toUpperCase()); break; case 4: System.out.println("enter your text"); t = text.next(); for (int i = 0; i < 5; i++) { System.out.println(t.charAt(i)); } System.out.println(StringUtils.capitalize(t.toLowerCase())); break; case 5: System.out.println("enter your text for substring eg:710340"); int a, b; crn = text.next(); System.out.println("enter the first digit"); a = text.nextInt(); System.out.println("enter the ending digit"); b = text.nextInt(); System.out.println(crn.substring(a, b)); break; case 6: System.out.println("enter your text for replace"); crn = text.next(); String old, ne; System.out.println("enter the string you want to replace"); old = text.next(); System.out.println("enter the new value"); ne = text.next(); System.out.println(crn.replace(old, ne)); break; case 7: System.out.println("enter your text"); t1 = text.next(); System.out.println("enter the character to find"); t = text.next(); System.out.println(t1.indexOf(t)); break; case 8: System.out.println("enter your text with white space"); t1 = text.next(); System.out.println(t1.trim()); break; default: System.out.println("invalid"); } System.out.println("do yo want to continue?y\n\t"); check = choice.next();
}
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package day08task01;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author Samikshya
*/
public class Day08Task01 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {String t1, t2, t, crn;
int c;
String check = "y";
Scanner text = new Scanner(System.in);
while (check.equalsIgnoreCase("y")) {
System.out.println("enter your choice");
System.out.println("1-string Concatinate\n2-string compare\n3- Touppercase\n4-CharAt\n5-substring\n6-Replace\n7-indexofChar\n8-trim");
Scanner choice = new Scanner(System.in);
c = choice.nextInt();
switch (c) {
case 1: {
System.out.println("enter your first text for concatenation");
t1 = text.next();
System.out.println("enter your second text for concatenation");
t2 = text.next();
System.out.println(t1.concat(t2));
}
break;
case 2:
System.out.println("enter your first text for comparision");
t1 = text.next();
System.out.println("enter your second text for comparision");
t2 = text.next();if (t1.equals(t2)) { System.out.println("same text"); } else { System.out.println("different text"); } break; case 3: System.out.println("enter your text to change into lower case "); t1 = text.next(); System.out.println(t1.toLowerCase()); System.out.println("enter your text to change into upper case "); t2 = text.next(); System.out.println(t2.toUpperCase()); break; case 4: System.out.println("enter your text"); t = text.next(); for (int i = 0; i < 5; i++) { System.out.println(t.charAt(i)); } System.out.println(StringUtils.capitalize(t.toLowerCase())); break; case 5: System.out.println("enter your roll no for substring eg:71033811"); int a, b; crn = text.next(); System.out.println("enter the first digit"); a = text.nextInt(); System.out.println("enter the ending digit"); b = text.nextInt(); System.out.println(crn.substring(a, b)); break; case 6: System.out.println("enter your text for replace"); crn = text.next(); String old, ne; System.out.println("enter the string you want to replace"); old = text.next(); System.out.println("enter the new value"); ne = text.next(); System.out.println(crn.replace(old, ne)); break; case 7: System.out.println("enter your text"); t1 = text.next(); System.out.println("enter the character to find"); t = text.next(); System.out.println(t1.indexOf(t)); break; case 8: System.out.println("enter your text with white space"); t1 = text.next(); System.out.println(t1.trim()); break; default: System.out.println("invalid"); } System.out.println("do yo want to continue?y\n\t"); check = choice.next();
}
}
-
}
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package day8task_1;
import java.util.Scanner;
/**
*
-
@author Anish
*/
public class Day8Task_1 {/**
- @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String l = "n";
do {
System.out.print("1: Concatination\n2: Comparision\n3: toUpperCase & toLowerCase\n4: charAT\n5: Substring\n6: Replace\n7: indexOf\n8: Trim\nEnter your choice: ");
Scanner in = new Scanner(System.in), s = new Scanner(System.in);
int ch = in.nextInt();
System.out.print("Enter your string: ");
String s2, s1 = s.nextLine();
switch (ch) {
case 1:
System.out.print("Enter your second string: ");
s2 = s.nextLine();
System.out.println("The concatinated string is: " + s1 + s2);
break;
case 2:
System.out.print("Enter your second string: ");
s2 = s.nextLine();
if (s1 == s2) {
System.out.println("The strings are same");
} else {
System.out.println("The string are different");
}
break;
case 3:
System.out.println("The give string in upper case is:" + s1.toUpperCase());
System.out.println("The give string in lower case is:" + s1.toLowerCase());
break;
case 4:
System.out.println("The characters of the string are:");
for (int i = 0; i < s1.length(); i++) {
System.out.println(s1.charAt(i));
}
break;
case 5:
System.out.print("Enter start and end index of substring:");
int st = in.nextInt(),
ed = in.nextInt();
System.out.println("The substring is:" + s1.substring(st, ed));
break;
case 6:
System.out.print("Enter the string you want to replace:");
String r = s.nextLine();
System.out.print("Enter the string you want to replace with:");
String rw = s.nextLine();
System.out.println("The result is:" + s1.replace(r, rw));
break;
case 7:
System.out.print("Enter search key:");
s2 = s.nextLine();
System.out.println("The index of search key is:" + s1.indexOf(s2));
break;
case 8:
System.out.println("The trimmed string is:" + s1.trim());
break;
default:
System.out.println("Invalid case");
break;
}
System.out.println("Do you want to continue??(Y/N)");
l = s.next();
} while (l.equalsIgnoreCase("y"));
}
- @param args the command line arguments
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package day8task10;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author kajal
*/
public class Day8Task10 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String s1, s2, t, crn;
int c;
String check = "y";
Scanner text = new Scanner(System.in);
while (check.equalsIgnoreCase("y")) {
System.out.println("enter your choice");
System.out.println("1-string Concatinate\n2-string compare\n3- Touppercase\n4-CharAt\n5-substring\n6-Replace\n7-indexofChar\n8-trim");
Scanner choice = new Scanner(System.in);
c = choice.nextInt();
switch (c) {
case 1: {
System.out.println("enter your first text for concatenation");
s1 = text.next();
System.out.println("enter your second text for concatenation");
s2 = text.next();System.out.println(s1.concat(s2)); break; } case 2: { System.out.println("enter your first text for compare"); s1 = text.next(); System.out.println("enter your second text for compare"); s2 = text.next(); if (s1.equalsIgnoreCase(s2)) { System.out.println("equal"); break; } } case 3: { System.out.println("enter your text"); s1 = text.next(); System.out.println(s1.toUpperCase()); break; } case 4: { System.out.println("enter your 4text "); s1 = text.next(); for (int i = 0; i < 5; i++) { System.out.println(s1.charAt(i)); } System.out.println(StringUtils.capitalize(s1.toLowerCase())); break; } case 5: { System.out.println("enter your text for substring eg:710331"); int a, b; crn = text.next(); System.out.println("enter the first digit"); a = text.nextInt(); System.out.println("enter the ending digit"); b = text.nextInt(); System.out.println(crn.substring(a, b)); break; } case 6: System.out.println("enter your string for replace"); crn = text.next(); String old, new_; System.out.println("enter the string you want to replace"); old = text.next(); System.out.println("enter the new value"); new_ = text.next(); System.out.println(crn.replace(old, new_)); break; case 7: System.out.println("enter your text"); s1 = text.next(); System.out.println("enter the character to find"); t = text.next(); System.out.println(s1.indexOf(t)); break; case 8: System.out.println("enter your text with white space1"); s1 = text.next(); System.out.println(s1.trim()); break; default: System.out.println("invalid"); } System.out.println("\ndo yo want to continue?y\n\t"); check = choice.next();
}
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package d8c1;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author praben shaiju
*/
public class D8c1 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
int a;
Scanner input=new Scanner(System.in);System.out.println("Input the value\n1)string concatenation\n2)string comparision\n3)string casing\n4)capitalization\n5)get char indexing\n6)substring\n7)string replacing\n8)Index of char\n9)trim");
a=input.nextInt();switch(a)
{case 1:System.out.println("enter any 3 strings"); String s1=input.next(); String s2=input.next(); String s3=input.next(); System.out.println(s1+s2); System.out.println(s1.concat(s2)); System.out.println(s1.concat(s2.concat(s3))); break; case 2:System.out.println("enter any 2 strings"); String t1=input.next(); String t2=input.next(); if(t1.equalsIgnoreCase(t2)) { System.out.println("success"); } else { System.out.println("failure"); } break; case 3:System.out.println("enter the string"); String T1=input.next(); System.out.println(T1.toUpperCase()); System.out.println(T1.toLowerCase()); System.out.println(T1); break; case 4:System.out.println("enter any string"); String n=input.next(); System.out.println(StringUtils.capitalize(n.toLowerCase())); break; case 5:System.out.println("enter any string"); String np=input.next(); System.out.println(np.charAt(3)); break; case 6:System.out.println("enter your college roll number"); String crn=input.next(); System.out.println(crn.substring(2)); System.out.println(crn.substring(3,5)); break; case 7:System.out.println("enter your college roll number"); String Crn=input.next(); System.out.println(Crn.replace("71","batch 71")); System.out.println(Crn.replaceAll(Crn, "0710319")); System.out.println(Crn); break; case 8:System.out.println("enter any string"); String t="test"; System.out.println(t.indexOf('t')); System.out.println(t.lastIndexOf('t')); System.out.println(t.indexOf("st")); break; case 9:System.out.println("enter any string"); String p=input.next(); System.out.println(p.trim()); break; default:System.out.println("invalid input");
}
// TODO code application logic here
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package assignment;
import java.util.Scanner;
import static jdk.nashorn.tools.ShellFunctions.input;
/**
*
-
@author DELL
*/
public class Assignment {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
Scanner st = new Scanner(System.in);
int n;
String s1, s2;
String check = "y";
while (check.equalsIgnoreCase("y")) {
System.out.println("Enter The choice : \n 1.Concatination\n 2.Comparison\n 3.To Uppercase or Lowercase\n 4.charAt\n 5.Substring\n 6.Replace\n 7.IndexofChar\n 8.Trim");
n = input.nextInt();
switch (n) {
case 1: {
System.out.println("Enter First string : ");
s1 = st.next();
System.out.println("Enter Second string : ");
s2 = st.next();
System.out.println(s1.concat(s2));
break;
}
case 2: {
System.out.println("Enter First string : ");
s1 = st.next();
System.out.println("Enter Second string : ");
s2 = st.next();if (s1.equalsIgnoreCase(s2)) { System.out.println("Equal"); } else { System.out.println("Not equal"); } break; } case 3: { System.out.println("Enter your string : "); s1 = st.next(); System.out.println("Uppercase : " + s1.toUpperCase()); System.out.println("Lowercase : " + s1.toLowerCase()); break; } case 4: { System.out.println("Enter your string : "); s1 = st.next(); for (int i = 0; i < 5; i++) { System.out.println(s1.charAt(i)); } break; } case 5: { System.out.println("Enter your college roll no : "); s1 = st.next(); System.out.println(s1.substring(0, 2)); System.out.println(s1.substring(3, 4)); System.out.println(s1.substring(4, 6)); System.out.println(s1.replace("71", "Batch 2077 ")); System.out.println(s1.replace("03", "Computer")); break; } case 6: { System.out.println("Enter your college year : "); s1 = st.next(); System.out.println(s1.replace("71", "Year 20" + s1)); break; } case 7: { System.out.println("enter your text"); s1 = st.next(); System.out.println("enter the character to find"); s2 = st.next(); System.out.println(s1.indexOf(s2)); break; } case 8: { System.out.println("Enter the string with space"); s1 = st.next(); System.out.println(s1.trim()); break; } default: { System.out.println("Invalid input!!!"); } } System.out.println("Would you like to continue?(y-n) \t"); check = input.next();
}
}
-
}
from java.
package stringop;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author Lenovo
*/
public class StringOp {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
Scanner inp = new Scanner(System.in);String S1, S2, check = "y";
System.out.println("Enter the strings S1");
S1 = in.nextLine();
System.out.println("Enter the next string S2");
S2 = in.nextLine();
do {
System.out.println("Enter the choices");
System.out.print("1. Concatenation\n2. Comparison\n3. Uppercase and lowercase\n4. CharAt(index)\n5. Substring\n6. Replace\n7. IndexOf(char)\n8. Trim\n");
int choice;
choice = inp.nextInt();
switch (choice) {
case 1:
System.out.println("After Concatinating");
System.out.println(S1 + S2);
System.out.println(S1.concat(S2));
break;
case 2:
System.out.println("After Comparing");
if (S1.equals(S2)) {
System.out.println("the strings are equal");
} else {
System.out.println("strings are unequal");
}
break;
case 3:
System.out.println("into Uppercase and lowercase");
System.out.println(S1.toUpperCase());
System.out.println(S2.toLowerCase());
System.out.println(StringUtils.capitalize(S1));
System.out.println(StringUtils.decapitalize(S2));
break;
case 4:
System.out.println("Characterwise listing");
for (int i = 0; i < S1.length(); i++) {
System.out.println(S1.charAt(i));
}
break;
case 5:
System.out.println("Substrings");
System.out.println(S1.substring(0, 3));
System.out.println(S1.substring(4, 6));
System.out.println(S1.substring(5, 8));
break;
case 6:
System.out.println("After replacing");
System.out.println(S1.replace("s", "sweet"));
System.out.println(S1.replace("d", "danger"));
System.out.println(S1.replace("ha", "hahaha"));
break;
case 7:
System.out.println("index of");
System.out.println(S1.indexOf("s"));
System.out.println(S1.indexOf("a"));
System.out.println(S1.lastIndexOf("d"));
System.out.println(S1.indexOf("ddha"));
break;
case 8:
System.out.println("After trimming");
System.out.println(S1.trim());
break;
default:
System.out.println("invalid input");
break;
}
System.out.println("Do you want to continue? (y/n)");
check = in.next();
} while (check.equalsIgnoreCase("y"));
}
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package ass.day8;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author nissus
*/
public class AssDay8 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
String s1,s2,s3,crn;
System.out.println("1.Concatenation");
System.out.println("2.Comparison");
System.out.println("3.toUpperCase");
System.out.println("4.toLowerCase");
System.out.println("5.Capitalize");
System.out.println("6.charAt(index)");
System.out.println("7.Substring");
System.out.println("8.Replace");
System.out.println("9.IndexOf(char),lastIndexOf(char)");
System.out.println("10.trim()");
System.out.println("Enter your choice");String check="y";
while (check.equalsIgnoreCase(check)){
Scanner input=new Scanner(System.in);
int n=input.nextInt();
switch(n){
case 1:
System.out.println("Enter first string to concatenate");
input=new Scanner(System.in);
s1=input.nextLine();
System.out.println("Enter second string to concatenate");input=new Scanner(System.in); s2=input.nextLine(); System.out.println("Enter third string to concatenate"); input=new Scanner(System.in); s3=input.nextLine(); System.out.println(s1.concat(s2.concat(s3))); break; case 2: System.out.println("Enter first string to compare"); input=new Scanner(System.in); s1=input.nextLine(); System.out.println("Enter second string to compare"); input=new Scanner(System.in); s2=input.nextLine(); if(s1.equalsIgnoreCase(s2)){ System.out.println("Equal");} else{ System.out.println("Not Equal"); } break; case 3: System.out.println("Enter string for UPPERCASE"); input=new Scanner(System.in); s1=input.nextLine(); System.out.println(s1.toUpperCase()); break; case 4: System.out.println("Enter string for lowercase"); input=new Scanner(System.in); s1=input.nextLine(); System.out.println(s1.toLowerCase()); break; case 5: System.out.println("Enter string to Capitalize"); input=new Scanner(System.in); s1=input.nextLine(); System.out.println(StringUtils.capitalize(s1.toLowerCase())); break; case 6: System.out.println("Enter string"); input=new Scanner(System.in); s1=input.nextLine(); int s=s1.length(); for (int i = 0; i < s; i++) { System.out.println(s1.charAt(i)); } break; case 7: System.out.println("Enter string"); input=new Scanner(System.in); crn=input.nextLine(); System.out.println(crn.substring(0,2)); System.out.println(crn.substring(3,4)); System.out.println(crn.substring(4,6)); break; case 8: crn="660346"; System.out.println(crn.replace("66","Batch 2066_")); System.out.println(crn.replace("03","_Computer")); break; case 9: s1="test"; System.out.println(s1.indexOf('t')); System.out.println(s1.lastIndexOf('t')); System.out.println(s1.indexOf("est")); break; case 10: System.out.println("Enter string with spaces"); input=new Scanner(System.in); crn=input.nextLine(); System.out.println(crn.trim());
}
System.out.println("Do you want to continue");
check=input.next();
}
// TODO code application logic here
}
-
}
from java.
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
String s1, s2, s3, s4, s5;
String check = "y";
while (check.equalsIgnoreCase("y")) {
System.out.print("enter ur choice\n"
+ "1:concatination\n"
+ "2:comparison\n"
+ "3:uppercae\n"
+ "4:lowercase\n"
+ "5index\n"
+ "6:substring\n"
+ "7:replace\n"
+ "8:indexof\n"
+ "9:trim\n");
int x = in.nextInt();
switch (x) {
case 1:
System.out.println("enter 1st string");
s1 = in.next();
System.out.println("2nd string");
s2 = in.next();
System.out.println("output:" + s1 + s2);
break;
case 2:
System.out.println("enter 1st string");
s1 = in.next();
System.out.println("2nd string");
s2 = in.next();
if (s1.equals(s2)) {
System.out.println("true");
} else {
System.out.println("false");
}
break;
case 3:
System.out.println("enter string for uppercase");
s3 = in.next();
System.out.println(s3.toUpperCase());
break;
case 4:
System.out.println("enter string for lowerrcase");
s3 = in.next();
System.out.println(s3.toLowerCase());
break;
case 5:
System.out.println("enter string");
s4 = in.next();
System.out.println(StringUtils.capitalize(s4.toLowerCase()));
break;
case 6:
System.out.println("enter substring ");
s4 = in.next();
System.out.println("enter start number");
int c = in.nextInt();
System.out.println("enter end number");
int p = in.nextInt();
System.out.println("output:" + s4.substring(c, p));
break;
case 7:
System.out.println("enter string");
s3 = in.next();
System.out.println(s3);
System.out.println("enter string u want replace");
s2 = in.next();
System.out.println(" to replace string ");
s4 = in.next();
System.out.println("output:" + s3.replace(s2, s4));
break;
case 8:
System.out.println("enter your text");
s1 = in.next();
System.out.println("enter the character to find");
s2 = in.next();
System.out.println(s1.indexOf(s2));
break;
case 9:
System.out.println("enter your text with space");
s1 = in.next();
System.out.println(s1.trim());
break;
default:
System.out.println("wrong input");
}
System.out.println("\ndo yo want to continue?y\n\t");
check = in.next();
}
}
from java.
CRN: 660303
After Replacing...
66Computer Computer - This is not good
Try to replace only department code by department name.
from java.
Run replace section of @Sudan15423 & optimize it.
@bsnarnzt1 also did that, so optimize & manage user interaction of her code.
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package javaapplication72;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author Kishorr
*/
public class JavaApplication72 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int no;
Scanner input = new Scanner(System.in);
String s1, s2, s3;
System.out.println("Enter First String");
s1 = input.next();
System.out.println("Enter Second String");
s2 = input.next();
System.out.println("Enter Third String");
s3 = input.next();
String crn = "710322";
String s4 = "test", s5 = "Test";System.out.println("enter your choice");
System.out.println("1. Concatenation");
System.out.println("2. Comparison");
System.out.println("3. toUpperCase, toLowerCase");
System.out.println("4. charAt(index)");
System.out.println("5. Substring");
System.out.println("6. Replace");
System.out.println("7. indexOf(char)");
System.out.println("8. trim");no = input.nextInt();
switch (no) {
case 1:
System.out.println(s1 + s2);
System.out.println(s1.concat(s2));
System.out.println(s1.concat(s2.concat(s3)));
break;case 2: if (s4.equalsIgnoreCase(s5)) { System.out.println("Equal"); } break; case 3: System.out.println(s4.toUpperCase()); System.out.println(s4.toLowerCase()); System.out.println(StringUtils.capitalize(s4.toLowerCase())); break; case 4: for (int i = 0; i < s5.length(); i++) { System.out.println(s5.charAt(i)); } break; case 5: System.out.println("Rollno" + crn); System.out.println("Batch is" + crn.substring(0, 2)); System.out.println("Department is" + crn.substring(3, 4)); System.out.println("Roll is" + crn.substring(4, 6)); break; case 6: System.out.println(crn.replace("71", "Batch 71")); break; case 7: String s = "rabin"; System.out.println(s.indexOf('r')); System.out.println(s.lastIndexOf('r')); System.out.println(s.lastIndexOf("in")); case 8: String nl = " Nepal "; System.out.println(nl.trim()); break; default: System.out.println("Invalid Choice");
}
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package batchdptroll;
import com.sun.org.apache.bcel.internal.generic.GOTO;
import java.util.Scanner;
import java.util.regex.Pattern;
/**
*
-
@author ragen
*/
public class BatchDptRoll {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {String s,dept,batch,roll,dept_name;
start:
System.out.println("Enter yOur College ID(6-digit)");
Scanner scanner = new Scanner(System.in);
String Col_roll = scanner.nextLine();
s=Col_roll;
int len=s.length();
if(Pattern.matches("[a-zA-Z]+", s) == true || len > 6)
{
System.out.println("Your enter Wrong Roll number");} else{ dept=s.substring(2,4); //for (int i = 0; i < len; i++) { // char s2=s.charAt(i); if (dept.equals("01")) { dept_name = "Civil Engineering";
} else if (dept.equals("02")) {
dept_name = "Architecture";
} else if (dept.equals("03")) {
dept_name = "Computer Engineering";
} else if (dept.equals("04")) {
dept_name = "Electronics Engineering";
} else {
dept_name = "No Such Department";
}
System.out.println("Batch: 20" + s.substring(0, 2));
System.out.println("Department: " + dept_name);
System.out.println("Rollno.: " + s.substring(4, 6));} }
}
-
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package stringoperationusingswitch;
import com.sun.xml.internal.ws.util.StringUtils;
import static java.lang.Integer.parseInt;
import static java.time.Clock.system;
import java.util.Scanner;
import javax.swing.JOptionPane;
/**
*
-
@author ragen
*/
public class StringOperationUsingSwitch {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int choice;
String s1,s=" Nepa l ";//string itself a class
String s2,s3;choice=parseInt(JOptionPane.showInputDialog(""
+ "Enter your Choice!!\n"
+ "1.Concatenation\n"
+ "2. comparison\n"
+ "3. toUppercase\n"
+ "4. charAt\n"
+ "5. Substring\n"
+ "6. Replace\n"
+ "7. IndexOf\n"
+ "8. Trim()"));
switch(choice){
case 1:/* s1=JOptionPane.showInputDialog("Enter First String"); s2= JOptionPane.showInputDialog("Enter Second String"); s3= JOptionPane.showInputDialog("Enter Third String"); *//* Scanner in=new Scanner(System.in); System.out.println("age"); int age=in.nextInt(); //System.out.println(age);
-
*/
System.out.println("Enter First String ");
Scanner scanner = new Scanner(System.in);
String str1 = scanner.nextLine();
System.out.println("Your First String is " + str1);
System.out.println("Enter Second String ");
String str2 = scanner.nextLine();
System.out.println("Your Second String is " + str2);
System.out.println("Enter Third String ");
String str3 = scanner.nextLine();
System.out.println("Your Third String is " + str3);
s1=str1;
s2=str2;
s3=str3;
System.out.println(s1+s2+s3);
System.out.println(s1.concat(s2));
System.out.println(s1.concat(s2.concat(s3)));
break;
case 2:
System.out.println("Enter First String ");
Scanner scann = new Scanner(System.in);
String st1 = scann.nextLine();
System.out.println("Your First String is " + st1);
System.out.println("Enter Second String ");
String st2 = scann.nextLine();
System.out.println("Your Second String is " + st2);
System.out.println("Enter Third String ");
String st3 = scann.nextLine();
System.out.println("Your Third String is " + st3);
s1=st1;
s2=st2;
s3=st3;
System.out.println(s1.equals(s2));
System.out.println(s1.equalsIgnoreCase(s2));
if(s1==s2)
{
System.out.println("Equal");
}
else{
System.out.println("Not Equal");}
if(s1.equals(s3)){
System.out.println("Right");
}
else{
System.out.println("Wrong");
}
break;
case 3:
System.out.println("Enter First String ");
Scanner scan = new Scanner(System.in);
String stt1 = scan.nextLine();
System.out.println("Your First String is " + stt1);
s1=stt1;
System.out.println(s1.toUpperCase());
System.out.println(s1.toLowerCase());
break;
case 4:
System.out.println("Enter First String ");
Scanner scan1 = new Scanner(System.in);
String st = scan1.nextLine();
System.out.println("Your First String is " + st);
s1=st;
for (int i = 0; i < s1.length(); i++) {
System.out.println(s1.charAt(i));
}
System.out.println(StringUtils.capitalize(s1.toLowerCase()));
break;
case 5:
System.out.println("Enter First String ");
Scanner scannn = new Scanner(System.in);
String strt1 = scannn.nextLine();
System.out.println("Your First String is " + strt1);
s3=strt1;
System.out.println(s3.substring(0,2));
System.out.println(s3.substring(4,2));
break;
case 6:
System.out.println("Enter First String ");
Scanner scannnn = new Scanner(System.in);
String strit1 = scannnn.nextLine();
System.out.println("Your First String is " + strit1);
s3=strit1;
System.out.println(s3.replace("20", "Twenty"));
break;
case 7:
System.out.println("Enter First String ");
Scanner scaner = new Scanner(System.in);
String strin1 = scaner.nextLine();
System.out.println("Your First String is " + strin1);
s1=strin1;
System.out.println(s1.indexOf('N'));
System.out.println(s1.lastIndexOf('L'));
break;
case 8:
System.out.println("Enter First String ");
Scanner scannner = new Scanner(System.in);
String string1 = scannner.nextLine();
System.out.println("Your First String is " + string1);
s1=string1;
System.out.println(s1.trim());
break;
}
}
from java.
package string.operation;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author PC
*/
public class StringOperation {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String t1, t2, t, crn;
int c;
String check = "y";
Scanner text = new Scanner(System.in);
while (check.equalsIgnoreCase("y")) {
System.out.println("enter your choice");
System.out.println("1-string Concatinate\n2-string compare\n3- Touppercase\n4-CharAt\n5-substring\n6-Replace\n7-indexofChar\n8-trim");
Scanner choice = new Scanner(System.in);
c = choice.nextInt();
switch (c) {
case 1: {
System.out.println("enter your first text for concatenation");
t1 = text.next();
System.out.println("enter your second text for concatenation");
t2 = text.next();
System.out.println(t1.concat(t2));
}
break;
case 2:
System.out.println("enter your first text for comparision");
t1 = text.next();
System.out.println("enter your second text for comparision");
t2 = text.next();if (t1.equals(t2)) { System.out.println("same text"); } else { System.out.println("different text"); } break; case 3: System.out.println("enter your text to change into lower case "); t1 = text.next(); System.out.println(t1.toLowerCase()); System.out.println("enter your text to change into upper case "); t2 = text.next(); System.out.println(t2.toUpperCase()); break; case 4: System.out.println("enter your text"); t = text.next(); for (int i = 0; i < 5; i++) { System.out.println(t.charAt(i)); } System.out.println(StringUtils.capitalize(t.toLowerCase())); break; case 5: System.out.println("enter your text for substring eg:710309"); int a, b; crn = text.next(); System.out.println("enter the first digit"); a = text.nextInt(); System.out.println("enter the ending digit"); b = text.nextInt(); System.out.println(crn.substring(a, b)); break; case 6: System.out.println("enter your text for replace"); crn = text.next(); String old, ne; System.out.println("enter the string you want to replace"); old = text.next(); System.out.println("enter the new value"); ne = text.next(); System.out.println(crn.replace(old, ne)); break; case 7: System.out.println("enter your text"); t1 = text.next(); System.out.println("enter the character to find"); t = text.next(); System.out.println(t1.indexOf(t)); break; case 8: System.out.println("enter your text with white space"); t1 = text.next(); System.out.println(t1.trim()); break; default: System.out.println("invalid"); } System.out.println("do yo want to continue?y\n\t"); check = choice.next();
}
}
-
}
from java.
package string.operation;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author PC
*/
public class StringOperation {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String t1, t2, t, crn;
int c;
String check = "y";
Scanner text = new Scanner(System.in);
while (check.equalsIgnoreCase("y")) {
System.out.println("enter your choice");
System.out.println("1-string Concatinate\n2-string compare\n3- Touppercase\n4-CharAt\n5-substring\n6-Replace\n7-indexofChar\n8-trim");
Scanner choice = new Scanner(System.in);
c = choice.nextInt();
switch (c) {
case 1: {
System.out.println("enter your first text for concatenation");
t1 = text.next();
System.out.println("enter your second text for concatenation");
t2 = text.next();
System.out.println(t1.concat(t2));
}
break;
case 2:
System.out.println("enter your first text for comparision");
t1 = text.next();
System.out.println("enter your second text for comparision");
t2 = text.next();if (t1.equals(t2)) { System.out.println("same text"); } else { System.out.println("different text"); } break; case 3: System.out.println("enter your text to change into lower case "); t1 = text.next(); System.out.println(t1.toLowerCase()); System.out.println("enter your text to change into upper case "); t2 = text.next(); System.out.println(t2.toUpperCase()); break; case 4: System.out.println("enter your text"); t = text.next(); for (int i = 0; i < 5; i++) { System.out.println(t.charAt(i)); } System.out.println(StringUtils.capitalize(t.toLowerCase())); break; case 5: System.out.println("enter your text for substring eg:710309"); int a, b; crn = text.next(); System.out.println("enter the first digit"); a = text.nextInt(); System.out.println("enter the ending digit"); b = text.nextInt(); System.out.println(crn.substring(a, b)); break; case 6: System.out.println("enter your text for replace"); crn = text.next(); String old, ne; System.out.println("enter the string you want to replace"); old = text.next(); System.out.println("enter the new value"); ne = text.next(); System.out.println(crn.replace(old, ne)); break; case 7: System.out.println("enter your text"); t1 = text.next(); System.out.println("enter the character to find"); t = text.next(); System.out.println(t1.indexOf(t)); break; case 8: System.out.println("enter your text with white space"); t1 = text.next(); System.out.println(t1.trim()); break; default: System.out.println("invalid"); } System.out.println("do yo want to continue?y\n\t"); check = choice.next();
}
}
-
}
from java.
CODE:
package stringoperation;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author User
*/
public class StringOperation {/**
- @param args the command line arguments
*/
public static void main(String[] args) {
- @param args the command line arguments
Scanner in = new Scanner(System.in);
Scanner inp = new Scanner(System.in);
String S1, S2, check = "y";
System.out.println("Enter the strings S1");
S1 = in.nextLine();
System.out.println("Enter the next string S2");
S2 = in.nextLine();
do {
System.out.println("Enter the choices");
System.out.print("1. Concatenation\n2. Comparison\n3. Uppercase and lowercase\n4. CharAt(index)\n5. Substring\n6. Replace\n7. IndexOf(char)\n8. Trim\n");
int choice;
choice = inp.nextInt();
switch (choice) {
case 1:
System.out.println("After Concatinating");
System.out.println(S1 + S2);
System.out.println(S1.concat(S2));
break;
case 2:
System.out.println("After Comparing");
if (S1.equals(S2)) {
System.out.println("the strings are equal");
} else {
System.out.println("strings are unequal");
}
break;
case 3:
System.out.println("into Uppercase and lowercase");
System.out.println(S1.toUpperCase());
System.out.println(S2.toLowerCase());
System.out.println(StringUtils.capitalize(S1));
System.out.println(StringUtils.decapitalize(S2));
break;
case 4:
System.out.println("Characterwise listing");
for (int i = 0; i < S1.length(); i++) {
System.out.println(S1.charAt(i));
}
break;
case 5:
System.out.println("Substrings");
System.out.println(S1.substring(0, 3));
System.out.println(S1.substring(4, 6));
System.out.println(S1.substring(5, 8));
break;
case 6:
System.out.println("After replacing");
System.out.println(S1.replace("s", "sweet"));
System.out.println(S1.replace("d", "danger"));
System.out.println(S1.replace("ha", "hahaha"));
break;
case 7:
System.out.println("index of");
System.out.println(S1.indexOf("s"));
System.out.println(S1.indexOf("a"));
System.out.println(S1.lastIndexOf("d"));
System.out.println(S1.indexOf("ddha"));
break;
case 8:
System.out.println("After trimming");
System.out.println(S1.trim());
break;
default:
System.out.println("invalid input");
break;
}
System.out.println("Do you want to continue? (y/n)");
check = in.next();
} while (check.equalsIgnoreCase("y"));
}
}
Output:
from java.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package task2;
import com.sun.xml.internal.ws.util.StringUtils;
import java.util.Scanner;
/**
*
-
@author admin
*/
public class Task2 {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice;
System.out.println("Enter the operation 1.concatination\t 2.comparision\t 3. toupperCase/toLowerCase 4.charAt\t 5.substring\t6.replace\t 7.indexOf\t 8.trim");
choice = input.nextInt();
switch (choice) {
case 1: {
// System.out.println("CONCATINATION");String s1, s2, s3; System.out.println("enter first string"); s1 = input.next(); System.out.println("enter 2nd string"); s2 = input.next(); System.out.println("enter 3rd string"); s3 = input.next(); System.out.println(s1 + s2); System.out.println(s1.concat(s2.concat(s3))); System.out.println(s1.concat(s2)); } break; case 2: { String s1, s2; System.out.println("enter first string"); s1 = input.next(); System.out.println("enter 2nd string"); s2 = input.next(); if (s1.equals(s2)) { System.out.println("return false"); } if (s1.equalsIgnoreCase(s2)) { System.out.println("return true"); } } break; case 3: { String s; System.out.println("enter string"); s = input.next(); System.out.println(s.toUpperCase()); System.out.println(s.toLowerCase()); break; } case 4: { String np; System.out.println("enter string"); np = input.next(); for (int i = 0; i < np.length(); i++) { System.out.println(np.charAt(i)); System.out.println(StringUtils.capitalize(np.toLowerCase())); } } break; case 5: { String crn; System.out.println("enter crn"); crn = input.next(); System.out.println(crn.substring(0, 2)); System.out.println(crn.substring(3, 4)); System.out.println(crn.substring(4, 6)); } break; case 6: { String crn; System.out.println("enter crn"); crn = input.next(); System.out.println(crn.replace("66", "Batch 2066")); System.out.println(crn.replace("03", "Computer")); } break; case 7: { String s; System.out.println("enter string"); s = input.next(); System.out.println(s.indexOf('t')); System.out.println(s.lastIndexOf('t')); System.out.println(s.indexOf("est")); } break; case 8: { String s; System.out.println("enter string to trim"); s = input.next(); System.out.println(s.trim()); } break;
}
}
-
}
from java.
Related Issues (20)
- Initial Design - CGPA Calculator HOT 1
- Initial Design - Blood Bank HOT 1
- Initial Design - CMS HOT 1
- Initial Design - RMS HOT 1
- Initial Design - SMS HOT 1
- Initial Design - FDC HOT 1
- Initial Design - HRS HOT 1
- Initial Design - DSMS HOT 1
- Some Screenshots - SRP HOT 1
- Some Screenshots - KLMS HOT 1
- Submit - Login UI HOT 6
- Build UI Better HOT 3
- Submit - Initial Screenshots, Source Code & Database HOT 4
- Submit - Concept Work of Your Project
- Design & Develop a Simple Calculator HOT 9
- Develop - PIN Breaker HOT 3
- Refresh JTable HOT 3
- Splash Screen - Loading
- Submit your Project Title HOT 26
- Project Submission Deadline: 31st Ashoj, 2017 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java.