Untitled Document
Untitled Document
import java.util.*;
class String{
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sentence:");
String s = sc.nextLine();
s = s + " ";
String w = "", maxW = "";
class Array {
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sentence:");
String s = sc.nextLine();
s = s + " ";
String w = "", rev = "";
import java.util.*;
class superspy {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n = sc.nextInt();
int c = 0;
int sum = 0;
while (n > 0) {
int r = n % 10;
sum = sum + r;
c++;
n = n / 10;
}
if (sum == c) {
System.out.println("superspy");
} else {
System.out.println("Not superspy");
}
}
}
4.
import java.util.*;
class automorphic{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n = sc.nextInt();
int c = 0;
int t = n;
while (n > 0) {
int r = n % 10;
c++;
n = n / 10;
}
int d =(int)Math.pow(10,c);
int s = t*t;
int l = s%d;
if (l == t) {
System.out.println("automorphic");
} else {
System.out.println("Not automorphic");
}
}
}
5.
import java.util.*;
class superspy {
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements:");
int n = sc.nextInt();
int arr[] = new int[n]; System.out.println("Enter the elements:");
int f = 0;
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) {
f = 1;
break;
}
}
if (f == 0) {
System.out.println("The array is sorted in ascending order.");
} else {
System.out.println("The array is not sorted in ascending order.");
}
}
}
6.
import java.util.*;
class binary {
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements:");
int n = sc.nextInt();
int arr[] = new int[n]; System.out.println("Enter the elements:");
break;
} else if (arr[mid] > k) {
l = mid - 1;
} else {
f = mid + 1;
}
}
if (f > l) {
System.out.println("Element not found");
}
}
}
7.
import java.util.*;
class Array {
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int n = sc.nextInt();
int arr[] = new int[n]; System.out.println("Enter the elements:");
if (f == -1) {
System.out.println("Element not found");
} else {
System.out.println("Element found at index: " + f);
}
}
}
8.
import java.util.*;
class spattern {
public static void main( ) {
String s = "ICSE";
int n = s.length();
import java.util.*;
class Pattern {
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1 for pattern 1 and 2 for pattern 2");
int check = sc.nextInt();
switch (check) {
case 1:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j % 2);
}
System.out.println();
}
break;
case 2:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print((char) (64 + j));
}
System.out.println();
}
break;
default:
System.out.println("Invalid choice");
break;
}
}
}
10..
import java.util.*;
class Array {
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements:");
int n = sc.nextInt();
int arr[] = new int[n];
int t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
}
}
}
import java.util.*;
class string {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sentence:");
String s = sc.nextLine(); // Use nextLine() to read the entire sentence
String res = " ";
s = " "+s;
int l = s.lastIndexOf(' ');
for(int i = 0; i<l; i++)
{
char c = s.charAt(i);
if(c == '.')
{
res = res+s.charAt(i+1) + ".";
}
}
res = res+s.substring(l);
System.out.println("result" +res);
}
}
12.
import java.util.*;
class Pattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1 for pattern 1 and 2 for pattern 2");
int check = sc.nextInt();
switch (check) {
case 1:
for (int i = 1; i <= 5; i++) {
for (int j = i; j >= 1; j--) {
System.out.print(j);
}
System.out.println();
}
break;
case 2:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j%2);
}
System.out.println();
}
break;
default:
System.out.println("Invalid choice");
break;
}
}
}
13.
import java.util.*;
class Pattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1 for pattern 1 and 2 for pattern 2:");
int check = sc.nextInt();
switch (check) {
case 1:
// Fibonacci Pattern
int a = 0, b = 1, c = 0;
case 2:
// Character Pattern
System.out.println("Character Pattern:");
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print((char) (64 + j));
}
System.out.println();
}
break;
default:
System.out.println("Invalid choice");
break;
}
}
}
14.
import java.util.*;
class StringCounter {
public static void main( ) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sentence:");
String s = sc.nextLine();
int l= 0, d = 0, sp = 0;
import java.util.*;
class spattern {
public static void main( ) {
String s = "BLUEJ";
int n = s.length();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(s.charAt(j-1)); }
System.out.println();
}
}