Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added my Day 6 code in Java #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions day6/Java/ThreeStrings1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* @date 16/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class ThreeStrings1 {

public static void main(String[] args) {
String s, s1=""; char ch, ch1; int l,i;
Scanner sc = new Scanner (System.in);
s = sc.nextLine();
s = ' '+ s;
l= s.length();
for(i=0; i<l; i++)
{
ch = s.charAt(i);
if(ch == ' ')
{
ch1= s.charAt(i+1);
s1 = s1+' '+ Character.toUpperCase(ch1);
i=i+1;
}
else
s1=s1+ch;
}
System.out.println("New string after changing the first character of every word to uppercase:");
System.out.println(s1);
}
31 changes: 31 additions & 0 deletions day6/Java/ThreeStrings2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* @date 16/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class ThreeStrings2 {

public static void main(String[] args) {
String s, s1=" ", s2=" "; int i, l; char ch;
Scanner sc = new Scanner (System.in);
System.out.println("Enter a string");
s = sc.nextLine();
s=s+' ';
l= s.length();

for (i=0; i<l;i++)
{
ch = s.charAt(i);
if(ch ==' ')
{
s2= s2+' '+s1;
s1=" ";
}
else
s1 =ch+s1;

}
System.out.println(s2);
}

}

59 changes: 59 additions & 0 deletions day6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,65 @@ first_str = gets().chomp
second_str = gets().chomp
puts "\nAre #{first_str} and #{second_str} anagrams? #{check_anagram(String.new(first_str), String.new(second_str))}"
```
/* @date 16/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class ThreeStrings1 {

public static void main(String[] args) {
String s, s1=""; char ch, ch1; int l,i;
Scanner sc = new Scanner (System.in);
s = sc.nextLine();
s = ' '+ s;
l= s.length();
for(i=0; i<l; i++)
{
ch = s.charAt(i);
if(ch == ' ')
{
ch1= s.charAt(i+1);
s1 = s1+' '+ Character.toUpperCase(ch1);
i=i+1;
}
else
s1=s1+ch;
}
System.out.println("New string after changing the first character of every word to uppercase:");
System.out.println(s1);
}
```
/* @date 16/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class ThreeStrings2 {

public static void main(String[] args) {
String s, s1=" ", s2=" "; int i, l; char ch;
Scanner sc = new Scanner (System.in);
System.out.println("Enter a string");
s = sc.nextLine();
s=s+' ';
l= s.length();

for (i=0; i<l;i++)
{
ch = s.charAt(i);
if(ch ==' ')
{
s2= s2+' '+s1;
s1=" ";
}
else
s1 =ch+s1;

}
System.out.println(s2);
}

}
```

### Have Another solution?

Expand Down