Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views5 pages

Assignment 6 ArianAlNahin

The document contains multiple Java programs that perform various string manipulations, including converting lowercase letters to uppercase, reversing strings, checking for palindromes, and validating passwords. Each program uses the Scanner class for input and implements different algorithms to achieve its specific functionality. The programs demonstrate basic control structures, string handling, and character manipulation in Java.

Uploaded by

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

Assignment 6 ArianAlNahin

The document contains multiple Java programs that perform various string manipulations, including converting lowercase letters to uppercase, reversing strings, checking for palindromes, and validating passwords. Each program uses the Scanner class for input and implements different algorithms to achieve its specific functionality. The programs demonstrate basic control structures, string handling, and character manipulation in Java.

Uploaded by

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

import java.util.

Scanner;
public class t11{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String result = "";
for (int i = 0; i < s.length(); i++){
char ch = s.charAt(i);
if (ch >= 97 && ch <= 122){
result += (char)(ch - 32);
}
else{
result += ch;
}
}
System.out.println(result);
}
}

import java.util.Scanner;
public class t12{
public static void main(String[]args){
Scanner input = new Scanner(System.in);
String original = input.nextLine();
String reverse = "";
int i = original.length() - 1;
while (i >= 0) {
reverse = reverse + original.charAt(i);
i--;
}
System.out.println(reverse);
}
}

import java.util.Scanner;
public class t13{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int start = 0;
int end = s.length() - 1;
boolean mm = true;
while(start < end){
if(s.charAt(start) != s.charAt(end)){
mm = false;
break;
}
start++;
end--;
}

if(mm){
System.out.println("true");
}
else{
System.out.println("false");
}
}
}

import java.util.Scanner;
public class t14{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
String ii = sc.nextLine();
char ss = sc.nextLine().charAt(0);
String temp = "";
for (int i = 0; i < ii.length(); i++) {
if (ii.charAt(i) == ss) {
if (temp.length() > 0) {
System.out.println(temp);
temp = "";
}
} else {
temp += ii.charAt(i);
}
}
if (temp.length() > 0) {
System.out.println(temp);
}
}
}

import java.util.Scanner;
public class t15{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
String temp = "";
String reversed = "";
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == ' ') {
if (temp != "") {
reversed = temp + " " + reversed;
temp = "";
}
}
else {
temp += input.charAt(i);
}
}
if (temp != "") {
reversed = temp + " " + reversed;
}
System.out.println(reversed);
}
}

import java.util.Scanner;
public class t16{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
String t=s.nextLine();
int v=0,c=0,i=0;
while(i<t.length()){
char ch=t.charAt(i);
if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z')){
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||
ch=='O'||ch=='U'){
v=v+1;
}
else{
c=c+1;
}
}
i=i+1;
}
if(v>0&&v%3==0&&c>0&&c%5==0){
System.out.println("Aaarr! Me Plunder!!");
}
else{
System.out.println("Blimey! No Plunder!!");
}
}
}

import java.util.Scanner;
public class t17{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String x = s.nextLine();
String y = s.nextLine();
String z = "";
for (int i = 0; i < x.length(); i++) {
char ch = x.charAt(i);
boolean f = false;
for (int j = 0; j < y.length(); j++) {
if (ch == y.charAt(j)) {
f = true;
break;
}
}
if (!f) {
z = z + ch;
}
}
for (int i = 0; i < y.length(); i++) {
char ch = y.charAt(i);
boolean f = false;
for (int j = 0; j < x.length(); j++) {
if (ch == x.charAt(j)) {
f = true;
break;
}
}
if (!f) {
z = z + ch;
}
}
String u = "";
for (int i = 0; i < z.length(); i++) {
char ch = z.charAt(i);
if (ch >= 'a' && ch <= 'z') {
u = u + (char)(ch - 32);
} else {
u = u + ch;
}
}
System.out.println(u);
}
}

import java.util.Scanner;
public class t18{
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
String a = x.nextLine();
String b = "";
int c = 0;
for (int i = 0; i < a.length(); i++) {
char d = a.charAt(i);
if ((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z')) {
if (c % 2 == 0) {
if (d >= 'A' && d <= 'Z') {
b = b + (char)(d + 32);
} else {
b = b + d;
}
} else {
if (d >= 'a' && d <= 'z') {
b = b + (char)(d - 32);
} else {
b = b + d;
}
}
c++;
} else {
b = b + d;
}
}
System.out.println(b);
}
}

import java.util.Scanner;
public class t19{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String p = s.nextLine();
int length = p.length();
if (length >= 8) {
boolean u = false;
boolean l = false;
boolean n = false;
boolean sc = false;
for (int i = 0; i < length; i++) {
char ch = p.charAt(i);
if (ch >= 'A' && ch <= 'Z') {
u = true;
} else if (ch >= 'a' && ch <= 'z') {
l = true;
} else if (ch >= '0' && ch <= '9') {
n = true;
} else {
sc = true;
}
}
if (u && l && n && sc) {
System.out.println("True");
} else {
System.out.println("False");
}
} else {
System.out.println("False");
}
}
}

import java.util.Scanner;
public class t20{
public static void main(String[]args) {
Scanner s = new Scanner(System.in);
String a = s.nextLine();
String b = s.nextLine();
boolean isValid = true;
for (int i = 0; i <= b.length() - a.length(); i++) {
int c = 0;
for (int j = 0; j < a.length(); j++) {
if (b.charAt(i + j) == a.charAt(j)) {
c++;
}
}
if (c == a.length()) {
isValid = false;
break;
}
}
if (isValid) {
System.out.println("Valid");
} else {
System.out.println("Invalid");
}
}
}

You might also like