0% found this document useful (0 votes)
23 views3 pages

String Programs

The document contains various Java logical programming examples that demonstrate string manipulation techniques. It includes reversing words in a string, changing the case of characters, summing numeric values from a string, and removing duplicate characters. Each example is accompanied by input strings and expected output results.

Uploaded by

akshaymkamble333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

String Programs

The document contains various Java logical programming examples that demonstrate string manipulation techniques. It includes reversing words in a string, changing the case of characters, summing numeric values from a string, and removing duplicate characters. Each example is accompanied by input strings and expected output results.

Uploaded by

akshaymkamble333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java logical programme akshay

Java logical Programme


String input = "my name is sourabh"; String input = "my name is sourabh";
// o/p = ym eman si hbaruos // o/p = sourabh is name my;

String ab[] = input.split(" "); String ab[] = input.split(" ");


StringBuilder sb = new StringBuilder();
for(String name :ab){ StringBuilder sb = new StringBuilder();
StringBuffer sb1 = new for(int i =ab.length-1;i>=0;i--){
StringBuffer(name);
sb.append(sb1.reverse().toString()).append( sb.append(ab[i]).append(" ");
" "); }
} System.out.println(sb.toString());
System.out.println(sb.toString()); }
}
String input = "my name is sourabh"; String input = "AaSSdd";
// o/p = my eman is sourabh; // o/p=aAssDD;
String ab[] = input.split(" "); StringBuilder sb = new StringBuilder(input);
for(int i =0;i<ab.length;i++){ for(int i =0;i<input.length();i++){
if(i==1){ if(Character.isUpperCase(input.charAt(i)))
StringBuilder sb = new { sb.setCharAt(i,Character.toLowerCase(input.charAt(i)
StringBuilder(ab[i]); ));}
ab[i]= sb.reverse().toString();
}} else{ sb.setCharAt(i,Character.toUpperCase(input.char
String output = String.join(" ",ab); At(i)));
System.out.println(output); }}
}; System.out.println(sb);
}
Java logical programme akshay

String input = "sj11I38h1h1"; String input = "my name is is sourabh";


// sum of 11+38+1+1=51; // o/p= my name is sourabh
String num[] = input.split("\\D"); String words[] = input.split(" ");
int sum = 0; Set<String> li = new LinkedHashSet<String>();
for(int i =0;i<num.length;i++){
if(!num[i].isEmpty()){ for(String a : words){
int a = Integer.parseInt(num[i]); li.add(a);
sum+=a; }
} String output = String.join(" ",li);
} System.out.println(output);
System.out.println(sum); }
}

String input = "AASSDD";


// o/p=ASD;
StringBuilder output = new StringBuilder();

for (int i = 0; i < input.length(); i++) {


char ch = input.charAt(i);

// Add the character only if it's not already


in the output

if (output.indexOf(String.valueOf(ch)) == -1)
{
output.append(ch);
}
}
System.out.println("Output: " +
output.toString()); // Output: ASD
}
Java logical programme akshay

You might also like