Upload files to "OOP/Java/Lab/Week9"
This commit is contained in:
parent
e9a4ce08c7
commit
cd43a87e9b
20
OOP/Java/Lab/Week9/arrange_array.java
Normal file
20
OOP/Java/Lab/Week9/arrange_array.java
Normal 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]+" ");
|
||||
}
|
||||
}
|
||||
}
|
15
OOP/Java/Lab/Week9/concat_5.java
Normal file
15
OOP/Java/Lab/Week9/concat_5.java
Normal 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);
|
||||
}
|
||||
}
|
27
OOP/Java/Lab/Week9/replacing.java
Normal file
27
OOP/Java/Lab/Week9/replacing.java
Normal 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);
|
||||
|
||||
}
|
||||
}
|
13
OOP/Java/Lab/Week9/telephone.java
Normal file
13
OOP/Java/Lab/Week9/telephone.java
Normal 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);
|
||||
}
|
||||
}
|
24
OOP/Java/Lab/Week9/three_letter.java
Normal file
24
OOP/Java/Lab/Week9/three_letter.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user