From 2b9a21ac6201fefaf9fe4e64c180acff3332025c Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Mon, 14 Oct 2024 02:40:08 +0530 Subject: [PATCH] Upload files to "OOP/Java/Lab/Week9" --- OOP/Java/Lab/Week9/counts.java | 26 ++++++ OOP/Java/Lab/Week9/menu_main2.java | 68 +++++++++++++++ .../Lab/Week9/palin_alpha_rev_concat.java | 82 +++++++++++++++++++ OOP/Java/Lab/Week9/search_name.java | 50 +++++++++++ 4 files changed, 226 insertions(+) create mode 100644 OOP/Java/Lab/Week9/counts.java create mode 100644 OOP/Java/Lab/Week9/menu_main2.java create mode 100644 OOP/Java/Lab/Week9/palin_alpha_rev_concat.java create mode 100644 OOP/Java/Lab/Week9/search_name.java diff --git a/OOP/Java/Lab/Week9/counts.java b/OOP/Java/Lab/Week9/counts.java new file mode 100644 index 0000000..d4fbcbc --- /dev/null +++ b/OOP/Java/Lab/Week9/counts.java @@ -0,0 +1,26 @@ +import java.util.Scanner; +class counts{ + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + System.out.println("Enter the Lines..."); + String str=in.nextLine(); + str.trim(); + int no=str.length(); + System.out.println("Number of characters="+no); + String arr[]=str.split(" "); + System.out.println("Number of words="+arr.length); + String lines[]=str.split("\\.",0); // as \. to put a full stop and \\. to recognize \. + System.out.println("Number of Lines="+lines.length); + char characters[]=new char[no]; + String lowstr=str.toLowerCase(); + lowstr.getChars(0, no, characters, 0); + int i,count=0; + for(i=0;i0) + { + String temp=arr[j]; + arr[j]=arr[j+1]; + arr[j+1]=temp; + } + } + } + return arr; + + } + static String reverse(String str) + { + StringBuffer rev=new StringBuffer(str); + rev.reverse(); + String revstr=rev.toString(); + return revstr; + } + static String concating(String str) + { + String rev=reverse(str); + return str+rev; + } + + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + System.out.println("Enter the String"); + String str=in.nextLine(); + char contin='y'; + while(contin=='y'){ + System.out.println("What do you want to do?1 for checking palindrome,2 for alphabetic,3 for reversing,4 for concatinatig with reverse"); + int choice=in.nextInt(); + switch(choice) + { + case 1: + { + System.out.println("String is a palindrome:"+palindrome(str)); + break; + } + case 2: + { + String arr[]=alphabetic(str); + System.out.println("String in alphabetic order:"); + for(int i=0;i