Upload files to "OOP/Java/Lab/Week9"

This commit is contained in:
Aadit Agrawal 2024-10-14 02:39:38 +05:30
parent e9a4ce08c7
commit cd43a87e9b
5 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import java.util.*;
public class arrange_array {
public static void main(String[] args) {
int n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter number of strings you would like");
n = Integer.parseInt(sc.nextLine());
System.out.println("Enter your strings");
String[] arr = new String[n];
for(int i = 0;i<n;i++){
arr[i] = sc.nextLine();
}
Collections.sort(arr);// or use some sorting technique with arr[i].compareTo(arr[i+1])
for(int i = 0;i<n;i++){
System.out.print(arr[i]+" ");
}
}
}

View File

@ -0,0 +1,15 @@
import java.util.Scanner;
public class concat_5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String concatString = "";
System.out.println("Enter five strings separately:");
for (int i = 1; i<= 5; i++) {
System.out.print("Enter string " + i + ": ");
String inputString = sc.nextLine();
concatString.concat(inputString);
}
System.out.println("Concatenated String: " + concatString);
}
}

View File

@ -0,0 +1,27 @@
import java.util.Scanner;
class replacing{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the Lines...");
String str=in.nextLine();
str.trim();
System.out.println("Enter the word to be removed");
String word=in.nextLine();
StringBuffer strbuf= new StringBuffer(str);
if(str.contains(word))
{
int index=str.indexOf(word);
int wlen=word.length();
String
String rep="";
for(int i=0;i<wlen;i++)
{
rep+="*";
}
strbuf.replace(index,index+wlen,rep);
}
System.out.println("Replaced String=\n"+strbuf);
}
}

View File

@ -0,0 +1,13 @@
import java.util.Scanner;
public class telephone{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the phone number as (555) 555-5555");
String phoneNumber = sc.nextLine();
phoneNumber = phoneNumber.replaceAll("[^0-9]", "");
String areaCode = phoneNumber.substring(0, 3);
String sevenDigit = phoneNumber.substring(3);
System.out.println("Area Code:"+areaCode);
System.out.println("Seven digit phone number:"+sevenDigit);
}
}

View File

@ -0,0 +1,24 @@
import java.util.Scanner;
public class three_letter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a five-letter word: ");
String word = sc.nextLine();
if (word.length() != 5) {
System.out.println("Please enter a valid five-letter word.");
} else {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5;s k++) {
if (i != j && j != k && i != k) {
String threeLetterWord = "" + word.charAt(i) + word.charAt(j) + word.charAt(k);
System.out.println(threeLetterWord);
}
}
}
}
}
}
}