0% found this document useful (0 votes)
18 views47 pages

Essential Java Code Examples

Uploaded by

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

Essential Java Code Examples

Uploaded by

woleni8582
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

IMPORTANT CODES IN JAVA

//import [Link];
////import [Link];
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
//// int n = [Link]();
// positive or negative number
// if(n>=0) {
// [Link]("positive number");
// }
// else{
// [Link]("negative number");
// }
// }
//}
// even or oddd number
// if (n % 2 == 0) {
// [Link]("even number");
// } else {
// [Link]("odd number");
// }
// }
//}
// sum of fisrt N natural numbers/sum of n natural numbers
// int sum = 0;
// for (int i = 1; i <= n; i++) {
// sum = sum + i;
// }
// [Link](sum);
// }
//}
// using formula
// int result = n * (n + 1) / 2;
// [Link](result);
// }
//}
// using recursion-display the n natural numbers
// static void sumOfNatural(int n) {
// if (n == 0) {
// return;
// }
// else{
// sumOfNatural(n-1);
// [Link](n+" ");
// }
// }
// public static void main(String[] args){
// Scanner sc=new Scanner([Link]);
// int n=[Link]();
// sumOfNatural(n);
// }
//}
// sum of numbers in a given range
// int sum = 0, start=5,end=15;
// for (int i = start; i <= end; i++) {
// sum = sum + i;
// }
// [Link](sum);
// }
//}
// greatest of two numbers
// int a = [Link]();
// int b = [Link]();
// if (a > b) {
// [Link](a + " is the greatest number");
// } else {
// [Link](b + " is the greatest number");
// }
// }
//}
// greatest of three numbers
// int c = [Link]();
// if (a > b && a > c) {
// [Link](a + " is the greatest number");
// } else if (b > a && b > c) {
// [Link](b + " is the greatest number");
// } else {
// [Link](c + " is the greatest number");
// }
// }
//}
// leap year or not
// int n = [Link]();
// if (n % 4 == 0 || n % 400 == 0 && n % 100 != 0) {
// [Link](n + " is the leap year");
// } else {
// [Link](n + " is not a leap year");
// }
// }
//}
// prime number or not
// int n = [Link]();
// if (n <= 0) {
// [Link](n + " is not a prime number");
// } else {
// int flag = 0;
// for (int i = 2; i < n; i++) {
// if (n % i == 0) {
// flag = 1;
// break;
// }
// }
// if (flag == 0) {
// [Link]("prime number");
// } else {
// [Link]("not a prime number");
// }
// }
// }
//}
// prime number within a given range
// int start = [Link](), end = [Link]();
// for (int i = start; i <= end; i++) {
// if (i > 1) {
// int flag = 0;
// for (int j = 2; j <= i / 2; ++j) {
// if (i % j == 0) {
// flag = 1;
// break;
// }
// }
// if (flag == 0) {
// [Link](i + " ");
// }
// }
// }
// }
//}
// reverse of a number
// int n = [Link]();
// int reverse = 0;
// while (n != 0) {
// int digit = n % 10;
// reverse = reverse * 10 + digit;
// n = n / 10;
// }
// [Link](reverse);
// }
//}
// sum of digits of a number
// int sum = 0;
// while (n > 0) {
// int digit = n % 10;
// sum = sum + digit;
// n = n / 10;
// }
// [Link](sum);
// }
//}
// Palindrome number
// int sum = 0;
// int temp = n;
// while (n != 0) {
// int digit = n % 10;
// sum = sum * 10 + digit;
// n = n / 10;
// }
// if (sum == temp) {
// [Link](temp + " is a palindrome number");
// } else {
// [Link](temp + " is not a palindrome number");
// }
// }
//}
// Armstrong number
// int sum = 0;
// int temp = n;
// while (n != 0) {
// int digit = n % 10;
// sum = sum + digit*digit*digit;
// n = n / 10;
// }
// if (sum == temp) {
// [Link](temp + " is a armstrong number");
// } else {
// [Link](temp + " is not a armstrong number");
// }
// }
//}
// Armstrong numbers in the given range
// int start = [Link](), end = [Link]();
// for (int i = start; i < end; i++) {
// int sum = 0;
// int temp = i;
// while (temp != 0) {
// int digit = temp % 10;
// sum = sum + (digit * digit * digit);
// temp = temp / 10;
// }
// if (sum == i) {
// [Link](i + " ");
// }
// }
// }
//}
// fibonacci series upto nth term or nth fibonacci number
// int n = [Link]();
// int n1 = 0, n2 = 1, n3;
// [Link](n1+" "+n2+" ");
// for (int i = 0; i <= n; i++) {
// n3 = n1 + n2;
// [Link](n3 + " ");
// n1 = n2;
// n2 = n3;
// }
// }
//}
// Factorial of a number
// int n = [Link]();
// int fact = 1;
// for (int i = 1; i <= n; i++) {
// fact = fact * i;
// }
// [Link](fact + " ");
// }
//}
// factorial of a number using the recursion
// static int factorial(int n) {
// if (n == 0) {
// return 1;
// } else {
// return n * factorial(n - 1);
// }
// }
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int num = [Link]();
// [Link](factorial(num));
// }
//}
// power of a number
// double a = [Link]();
// double b = [Link]();
// double result = [Link](a, b);
// [Link](result);
// }
//}
// factor of a number
// int n = [Link]();
// for (int i = 1; i <= n; i++) {
// if (n % i == 0) {
// [Link](i + " ");
// }
// }
// }
//}
// prime factors of a number
// for (int i = 2; i < n; i++) {
// if (n % i == 0) {
// [Link](i + " ");
// n=n/i;
// }
// }
// if(n>2){
// [Link](n+" ");
// }
// }
//}
// Strong number or not a strong number
// int temp = n;
// int sum = 0;
// while (temp!= 0) {
// int digit = temp% 10;
// int fact = 1;
// for (int i = 2; i <= digit; i++){
// fact = fact * i;
// }
// sum = sum + fact;
// temp= temp / 10;
// }
// if(sum==n) {
// [Link](n+ " is a strong number");
// } else {
// [Link](n+ " is not an strong number");
// }
//// }
//}
// perfect number or not a perfect number
// int temp = n;
// int sum = 0;
// for (int i = 1; i < n; i++) {
// if (n % i == 0) {
// sum = sum + i;
// }
// }
// if (sum == temp) {
// [Link](temp + " is a perfect number");
// } else {
// [Link](temp + " is not a perfect number");
// }
// }
//}
// perfect square number
// double n = [Link]();
// double res = ([Link](n));
// [Link]((int) res);
// if (n == (res * res)) {
// [Link](n + " is a perfect square number");
// } else {
// [Link](n + " is not a perfect square number");
// }
// }
//}
// Automorphic number
// int n = [Link]();
// int res =n*n;
// int digit = res % 10;
// if (n == digit) {
// [Link](n + " is a automorphic number");
// } else {
// [Link](n + " is not a automorphic number");
// }
// }
//}
// Harshad number
// int n = [Link]();
// int temp=n;
// int sum = 0;
// while (n != 0) {
// int digit = n % 10;
// sum = sum + digit;
// n=n/10;
// }
// if (temp % sum == 0) {
// [Link](temp + " is a harshad number");
// } else {
// [Link](temp + " is not a harshad number");
// }
// }
//}
// Abundant number
// int n = [Link]();
// int sum = 0;
// for (int i = 1; i < n; i++) {
// if (n % i == 0) {
// sum = sum + i;
// }
// }
// if (sum > n) {
// [Link](n + " is a abundant number");
// } else {
// [Link](n + " is not a abundant number");
// }
// }
//}
// Friendly pair
// int n1 = [Link]();
// int n2 = [Link]();
// int sum1 = 0;
// for (int i = 1; i < n1; i++) {
// if (n1 % i == 0) {
// sum1 = sum1 + i;
// }
// }
// int sum2 = 0;
// for (int i = 1; i < n2; i++) {
// if (n2 % i == 0) {
// sum2 = sum2 + i;
// }
// }
// int res1 = sum1 / n1;
// int res2 = sum2 / n2;
// if (res1 == res2) {
// [Link](n1 + " " + n2 + " are friendly pair");
// } else {
// [Link](n1 + " " + n2 + " are not friendly pair");
// }
// }
//}
// HCF of two numbers/or also called as the gcd(greatest common divisior)
// int num1 = 36, num2 = 24, hcf = 1;
// for (int i = 1; i <= num1 || i <= num2; i++) {
// if (num1 % i == 0 && num2 % i == 0) {
// hcf = i;
// }
// }
// [Link](hcf);
// }
//}
// lcm of two numbers
// int num1 = 36, num2 = 24, hcf = 1;
// for (int i = 1; i <= num1 || i <= num2; i++) {
// if (num1 % i == 0 && num2 % i == 0) {
// hcf = i;
// }
// }
// int lcm=(num1*num2)/hcf;
// [Link]("lcm of two numbers is"+lcm);
// }
//}
// binary to decimal conversion
// int binary = [Link]();
// int decimal = 0;
// int n = 0;
// while (binary != 0) {
// int digit = binary % 10;
// decimal += digit * [Link](2,n);
// binary = binary / 10;
// n++;
// }
// [Link](decimal);
// }
//}
// hexadecimal to decimal number
// int hexadecimal = [Link]();
// int decimal = 0;
// int n = 0;
// while (hexadecimal != 0) {
// int digit = hexadecimal % 10;
// decimal += digit * [Link](8,n);
// hexadecimal = hexadecimal / 10;
// n++;
// }
// [Link](decimal);
// }
//}
// Hexadecimal to decimal conversion
// int hexadecimal = [Link]();
// int decimal = 0;
// int n = 0;
// while (hexadecimal != 0) {
// int digit = hexadecimal % 10;
// decimal += digit * [Link](16,n);
// hexadecimal = hexadecimal / 10;
// n++;
// }
// [Link](decimal);
// }
//}
// decimal to binary conversion
// int n = [Link]();
// String result = "";
// while (n >=1) {
// int digit = n % 2;
// n = n / 2;
// result = digit+result;
// }
// [Link](result);
// }
//}
// decimal to octal conversion
// int n = [Link]();
// String result = "";
// while (n >= 1) {
// int digit = n % 8;
// n = n / 8;
// result = digit + result;
// }
// [Link](result);
// }
//}
// decimal to hexadecimal
// int n = [Link]();
// String result = "";
// while (n >= 1) {
// int digit = n % 16;
// n = n / 16;
// result = digit + result;
// }
// [Link](result);
// }
//}
// binary to octal
// steps:binary to decimal and decimal to octal
// int binary = [Link]();
// int n = 0;
// int decimal = 0;
// while (binary > 0) {
// int digit = binary % 10;
// decimal += digit * [Link](2, n);
// binary = binary / 10;
// n++;
// }
// [Link](decimal);
// int n = [Link]();
// String result = "";
// while (n >= 1) {
// int digit = n % 8;
// n = n / 8;
// result = digit + result;
// }
// [Link](result);
// }
//}
// octal to binary conversion=octal to decimal and then decimal to binary
// int octal= [Link]();
// int n = 0;
// int decimal = 0;
// while (octal > 0) {
// int digit = octal % 10;
// decimal += digit * [Link](8, n);
// octal = octal / 10;
// n++;
// }
// [Link](decimal);
// int n = [Link]();
// String result = "";
// while (n >= 1) {
// int digit = n % 16;
// n = n / 16;
// result = digit + result;
// }
// [Link](result);
// }
//}
// points lies in which quadrant
// int x = [Link]();
// int y = [Link]();
// if (x > 0 && y > 0) {
// [Link](x + " , " + y + " lies on the quadrant one");
// } else if (x < 0 && y > 0) {
// [Link](x + " , " + y + " lies on the quadrant two");
// } else if (x < 0 && y < 0) {
// [Link](x + " , " + y + " lies on the quadrant three");
// } else {
// [Link](x + " , " + y + " lies on the quadrant four");//x>0 and y<0
// }
// }
//}
// permutation like n people occupy r places in a class in java
// int n = [Link]();
// int r = [Link]();
// int fact1 = 1;
// for (int i = 2; i <= n; i++) {
// fact1 = fact1 * i;
// }
// int fact2 = 1;
// for (int i = 2; i <= (n - r); i++) {
// fact2 = fact2 * i;
// }
// int result = fact1 / fact2;
// [Link](result);
// }
//}
// Maximum number of handshakes
// formual is there to find the number of handshakes
// int N = [Link]();
// int handshakes = N * (N - 1) / 2;
// [Link](handshakes);
// }
//}
// addition of two fractions
// int num1 = [Link]();
// int den1 = [Link]();
// int num2 = [Link]();
// int den2 = [Link]();
// int numerator3 = ((num1 * den2) + (num2 * den1));
// int denominator3 = den1 * den2;
// [Link](numerator3 + "/" + denominator3);
// }
//}
// replace 0's with 1's and viceversa
// int n = [Link]();
// int result=0;
// int place=1;
// while (n > 0) {
// int digit = n % 10;
// if (digit == 0) {
// digit = 1;
// }
// result=result+(digit*place);
// place=place*10;
// n = n / 10;
// }
// [Link](result);
// }
//}
// program to express the number as sum of two prime numbers
// static int isPrime(int n) {
// int flag = 0;
// for (int i = 2; i < n; i++) {
// if (n % i == 0) {
// flag = 1;
// break;
// }
// }
// return flag;
// }
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int flag = 0;
// for (int i = 2; i <= n / 2; i++) {
// if (isPrime(i)==0) {
// if (isPrime(n - i)==0) {
// [Link](n + "=" + i +" +"+ (n - i));
// flag = 1;
// }
// }
// }
// if (flag == 0) {
// [Link](n + " cannot be represnted in the form of sum of two prime
numbers");
// }
// }
//}
// area of a circle
// double r = [Link]();
// double area = 3.14* r * r;
// [Link]("area of circle is " + [Link](area));
// }
//}
// calculate number of digits in an integer
// int n = [Link]();
// int count = 0;
// while (n != 0) {
// int digit = n % 10;
// count++;
// n = n / 10;
// }
// [Link](count);
// }
//}
// convert numbers/digits to words(in the rane of (0-99)
// int n=[Link](); //for example=12
// int n1=n,n2=n;//12
// int a=n1%10,b=n2/10;//a=2,b=1
// String[] onesplace=new
String[]{"zero","one","two","three","four","five","six","seven","eight","nine"};
// String[] tensplace=new
String[]{"","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","ei
ghteen","ninteen"};
// String[] hundredsplace=new String[]{" ","
","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
// if(b==1) { //b==1 true
// [Link](tensplace[a+1]);//2+1=3
// }
// else if(a==0) { //not excecuted
// [Link](hundredsplace[b]);
// }
// else {
// [Link](hundredsplace[b] + "-" + onesplace[a]);
// }
// }
//}
// print number of days in a month
// int month = [Link]();
// int year = [Link]();
// if (month==2&&year % 4 == 0 || year % 400 == 0 && year % 100 != 0) {
// [Link]("29 days are there in that month");
// }
// else if(month==2) {
// [Link]("28 days in a month");
// }
// else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 9 ||
month == 11) {
// [Link]("31 days are there in given month");
// } else {
// [Link]("30 days are there in a given month");
// }
// }
//}
// counting the frequency of a particular number in the given number
// int n = [Link]();
// int count = 0;
// int d = 9;
// while (n != 0) {
// int digit = n % 10;
// if (digit == d) {
// count++;
// }
// n = n / 10;
// }
// [Link](count);
// }
//}
// counting the frequency of the digits in the given number
// int n = [Link]();
// int count[] = new int[10];
// while (n != 0) {
// int digit = n % 10;
// count[digit]++;
// n = n / 10;
// }
// for (int i = 0; i < 10; i++) {
// if (count[i] > 0) {
// [Link]("digit "+i+"-->"+count[i]+" times");
// }
// }
// }
//}
// count the integers that has exactly x divisiors
// int n = [Link]();
// int x = [Link]();
// int count = 0;
// for (int i = 1; i <= n; i++) { //1 to 8
// int count_digits = 0;
// for (int j = 1; j <= i; j++) { // 1 to 8
// if (i % j == 0) {
// count_digits++;
// }
// }
// if (count_digits == x) {
// count++;
// }
// }
// [Link](count);
// }
//}
// double a = [Link]();
// double b = [Link]();
// double c = [Link]();
// double determinant = (b * b) - 4 * a * c;
// if (determinant > 0) {
// double root1 = -b + [Link](determinant) / (2 * a);
// double root2 = -b - [Link](determinant) / (2 * a);
// [Link]("The roots are real and distinct");
// [Link](root1 + "," + root2 + " are the roots");
// } else if (determinant == 0) {
// double root1 = -b / (2 * a);
// [Link](root1 + " it has only one real root");
// } else {
// double root1 = -b / (2 * a);
// double root2 = [Link](-determinant) / (2 * a);
// [Link]("roots are imaginary");
// [Link]([Link](root1) + "+" + "i" + [Link](root2));
// }
// }
//}
// power of a number without using any inbuilt functions/means using recursion we solve
the problem
// double a = [Link]();
// double b = [Link]();
// [Link](powerofnumber(a,b));
// }
// static double powerofnumber(double a,double b) {
// if (b == 0) {
// return 1;
// } else {
// return a * powerofnumber(a, b - 1);
// }
// }
//}
// largest element in the array-method 1
// int n = [Link]();
// int a[] = new int[n];
// for (int i = 0; i < n; i++) {
// a[i] = [Link]();
// }
// [Link](a);
// [Link]([Link](a));
// int largest = a[n - 1];
// [Link](largest);
// }
//}
// int ans=a[0];
// for(int i=1;i<n;i++) {
// if (ans < a[i]) {
// ans=a[i];
// }
// }
// [Link](ans+" ");
// }
//}
// smallest element in the array
// int ans=a[0];
// for(int i=1;i<n;i++) {
// if (ans > a[i]) {
// ans=a[i];
// }
// }
// [Link](ans+" ");
// }
////}
// [Link](a);
// [Link]([Link](a));
// int smallest = a[0];
// [Link](smallest);
// }
//}
// calculate the length of the string without using length() function
// import [Link];
// public class importantcoding {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// int count = 0;
// for (int i = 0; i < [Link](); i++) {
// count++;
// }
// [Link](count);
// }
// }
//palindrome strings
//import [Link];
//public class importantcoding {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// char[] arr = [Link]();
// [Link](palindrome(arr));
// }
//
// static boolean palindrome(char[] arr) {
// int left = 0;
// int right = [Link] - 1;
// while (left < right) {
// if (arr[left] != arr[right]) {
// return false;
// } else {
// left++;
// right--;
// }
// }
// return true;
// }
//}
//import [Link];
//public class codes100{
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int marks[] = new int[n];
// for (int i = 0; i < n; i++) {
// marks[i] = [Link]();
// }
// int count = 0;
// int ans = marks[0];
// for (int i = 1; i < n; i++) {
// if (ans == marks[i]) {
// count++;
// }
// }
// if (count > 0) {
// count++;
// }
// [Link](count);
// }
//}
// arrays programs-largest element in the array
//import [Link];
//import [Link];
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int a[] = new int[n];
// for (int i = 0; i < n; i++) {
// a[i] = [Link]();
// }
// [Link](a);
// [Link]([Link](a));
// int result = a[n - 1];
// [Link](result);
// }
//}
// int ans=a[0];
// for(int i=1;i<n;i++){
// if(ans<a[i]){
// ans=a[i];
// }
// }
// [Link](ans);
// }
//}
//arrays-samllest element in the array
// [Link](a);
// [Link]([Link](a));
// int result = a[0];
// [Link](result);
// }
//}
// int ans = a[0];
// for (int i = 1; i < n; i++) {
// if (ans > a[i]) {
// ans = a[i];
// }
// }
// [Link](ans);
// }
//}
// combinationn of smallest and largest element in the array
// int ans=a[0];
// for(int i=1;i<n;i++){
// if(ans<a[i]){
// ans=a[i];
// }
// }
// [Link](ans);
// for (int i = 1; i < n; i++) {
// if (ans > a[i]) {
// ans = a[i];
// }
// }
// [Link](ans);
// }
//}
// Second largest element in the array
// [Link](a);
// [Link]([Link](a));
// int result = a[1];
// [Link](result);
// }
//}
// [Link](a);
// [Link]([Link](a));
// int result = a[n-2];
// [Link](result);
// }
//}
// sum of the elements in the array
// int sum = 0;
// for (int i = 0; i < n; i++) {
// sum = sum + a[i];
// }
// [Link](sum);
// }
//}
// Reverse of an array-method 1
// int start = 0;
// int end = [Link] - 1;
// while (start < end) {
// int temp = a[start];
// a[start] = a[end];
// a[end] = temp;
// start++;
// end--;
// }
// for(int i=0;i<n;i++)
// [Link](a[i]+" ");
// }
//}
// method-2 for reverse of an array
// for (int i = [Link] - 1; i >= 0; i--) {
// [Link](a[i] + " ");
// }
// }
//}
// sort the first half in ascending order and second half in descending order
// [Link](a);
// [Link]([Link](a));
// for (int i = 0; i < n / 2; i++) {
// [Link](a[i]+" ");
// }
// for (int j = n-1; j >=n/2; j--) {
// [Link](a[j]+" ");
// }
// }
//}
//sort the array:method-1 using the bubble sort or any sorting algorithms
//import [Link];
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// int[] a = {5, 4, 1,3,2};
// bubblesort(a);
// [Link]([Link](a));
// }
// static void bubblesort(int[] a) {
// for (int i = 0; i < [Link]; i++) {
// int swap = 0;
// for (int j = 1; j < [Link] - i; j++) {
// if (a[j-1] > a[j]) {
// int temp = a[j-1];
// a[j-1] = a[j];
// a[j] = temp;
// swap = 1;
// }
// }
// if (swap == 0) {
// break;
// }
// }
// }
//}
// finding frequency of the number in the array
// for (int i = 0; i < n; i++) {
// int flag = 0;
// int count = 0;
// for (int j = i + 1; j < n; j++) {
// if (a[i] == a[j]) {
// flag = 1;
// break;
// }
// }
// if (flag == 1)
// continue;
// for (int j = 0; j <= i; j++) {
// if (a[i] == a[j])
// count++;
// }
// [Link](a[i] + " : " + count);
// }
// }
//}
// anagrams
//import [Link];
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String str1 = [Link](); // eat
// String str2 = [Link](); // ate
// if ([Link]() == [Link]()) {
// char char1[] = [Link]();
// char char2[] = [Link]();
// [Link](char1);
// [Link](char2);
// boolean result = [Link](char1, char2);
// if (result) {
// [Link]("Anagrams");
// } else {
// [Link]("Not Anagrams");
// }
// } else {
// [Link]("Not Anagram");
//
// }
// }
//}
//java program for the checking whether the given character is uppercase or lowercase
//import [Link];
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// char ch = [Link]().charAt(0);
// if (ch >='A' && ch <= 'Z') {
// [Link](1);
// } else if (ch >= 'a' && ch <= 'z') {
// [Link](0);
// } else {
// [Link](-1);
// }
// }
//}
//import [Link].*;
//import [Link];
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int[] arr = new int[n];
// for (int i = 0; i < n; i++) {
// arr[i] = [Link]();
// }
// [Link](arr);
// [Link]([Link](arr));
// int ans = arr[0];
// int result = arr[n - 1] + arr[n - 2];
// [Link](result);
// }
//}
//import [Link];
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int count = 0;
// int number=[Link]();
// while(n!=0){
// int digit=n%10;
// if(digit==number){
// count++;
// }
// n=n/10;
// }
// [Link](count);
// }
//}
// calculate the number of vowels and consonants in the given string
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String str = [Link]();
// int vowelcount = 0, consonantcount = 0,whitespaces=0;
// for (int i = 0; i < [Link](); i++) {
// char ch=[Link](i);
// if (ch== 'a'|| ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') {
// vowelcount++;
// }
// else if(ch==' '){
// whitespaces++;
// }
// else {
// consonantcount++;
// }
// }
// [Link]("number of vowels "+vowelcount);
// [Link]("number of consonants "+consonantcount);
// [Link]("number of white spaces "+whitespaces);
// }
//}
//find the ascii value of the character-using type casting we can achieve the following code
//import [Link];
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// char ch = [Link]().charAt(0);
// int result=ch;
// [Link](result); //ascii value of lowercase letter starts from 97 and
uppercase starts from 65
// }
//}
//remove the vowels from the given string
//import [Link];
//import [Link].*;
//public class codes100{
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// String str=[Link]();
// String result=[Link]("[aeiouAEIOU]","");
// [Link](result);
// }
//}
//import [Link];
//import [Link].*;
//public class codes100{
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// String str=[Link]();
// String result=[Link](" ","");
// [Link](result);
// }
//}
//import [Link];
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// StringBuffer string = new StringBuffer();
// String str1 = [Link]();
// [Link]();
// for (int i = 0; i < [Link](); i++) {
// if ([Link](i) >= 'a' || [Link](i) <= 'z') {
// [Link]([Link](i));
// }
// }
// }
//}
//sum of the unique elements in the array
//import [Link].*;
//public class codes100{
// public static void main(String[] args){
// Scanner sc=new Scanner([Link]);
// int n=[Link]();
// int[] arr=new int[n];
// for(int i=0;i<[Link];i++){
// arr[i]=[Link]();
// }
// int sum=0;
// for( int i=0;i<[Link];i++){
// int j;
// for(j=0;j<i;j++){
// if(arr[i]==arr[j]){
// break;
// }
// }
// if(i==j){
// sum+=arr[i];
// }
// }
// [Link](sum);
// }
//}
//print the sum of prime index elements in the array
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int[] arr = new int[n];
// for (int i = 0; i < [Link]; i++) {
// arr[i] = [Link]();
// }
// int sum = 0;
// for (int i = 2; i < [Link]; i++) {
// int flag = 0;
// for (int j = 2; j <=[Link](i); j++) {
// if (i % j == 0) {
// flag = 1;
// break;
// }
// }
// if (flag == 0) {
// sum = sum + arr[i];
// }
// }
// [Link](sum);
// }
//}
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// float f = [Link]();
// float result = (int) (3.14 * f * f);
// [Link](result);
// }
//}
//counting the unique elments/distinct elements in the array
//import [Link].*;
//public class codes100{
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// int n=[Link]();
// int[] arr=new int[n];
// for(int i=0;i<[Link];i++) {
// arr[i] = [Link]();
// }
// int count=0;
// for(int i=0;i<[Link];i++){
// int j;
// for( j=0;j<i;j++){
// if(arr[i]==arr[j]){
// break;
// }
// }
// if(i==j){
// count++;
// }
// }
// [Link](count);
// }
//}
//program for counting the number of odd and even elements in the array
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int[] arr = new int[n];
// for (int i = 0; i < [Link]; i++) {
// arr[i] = [Link]();
// }
// int oddcount = 0, evencount = 0;
// for (int i = 0; i < [Link]; i++) {
// if (arr[i] % 2 == 0) {
// oddcount++;
// } else {
// evencount++;
// }
// }
// [Link](oddcount);
// [Link](evencount);
// }
//}
//****two pointer techinque****for removing the duplicate elements from the sorted array
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// int[] arr = {1, 1, 2, 2, 3, 4, 5,5,6, 6};
// int newlength=removeduplicate(arr);
// for (int i = 0; i < newlength; i++) {
// [Link](arr[i]+" ");
// }
// }
// static int removeduplicate(int[] arr) {
// if([Link]==0){
// return -1;
// }
// int rd = 0;
// for (int i = 1; i < [Link]; i++) {
// if (arr[rd] != arr[i]) {
// rd++;
// arr[rd] = arr[i];
// }
// }
// return rd+ 1;
// }
//}
//swapping of two numbers using different methods
//import [Link];
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int a = [Link]();
// int b = [Link]();
//// first method-using temporary variable
// int temp = a;
// a = b;
// b = temp;
//// second method using arithmetic operators
// a=a+b;
// b=a-b;
// a=a-b;
//// third method also using arithemtic operators
// a=a*b;
// b=a/b;
// a=a/b;
//// fourth method-using bitwise operators
// a=a^b;
// b=a^b;
// a=a^b;
// [Link]("after swapping a is " + a);
// [Link]("after swapping b is " + b);
// }
//}
//remove the duplicates from the array using the hashset
//import [Link].*;
//public class codes100{
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int[] a = new int[n];
// Set hash = new HashSet<>();
// for (int i = 0; i < [Link]; i++) {
// a[i] = [Link]();
// [Link](a[i]);
// }
// [Link](hash);
// }
//}
//fibonacci number using the recursion in java
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// [Link](fibonacci(n));
// }
// static int fibonacci(int n) {
// if (n == 0) {
// return 0;
// }
// else if(n==1){
// return 1;
// }
// else {
// return fibonacci(n-1) + fibonacci(n - 2);
// }
// }
//}
//sum of the natural numbers uisng the recursion
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// [Link](sumofnnatural(n));
// }
// static int sumofnnatural(int n) {
// if (n == 0) {
// return 0;
// } else if (n == 1) {
// return 1;
// } else {
// return n + sumofnnatural(n - 1);
// }
// }
//}
//display the natural numbers using the recursion
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// sumofnnatural(n);
// }
// static void sumofnnatural(int n){
//// if (n >= 1) {
//// [Link](n + " ");
//// sumofnnatural(n - 1); //it will print the natural numbers in the reverse
// if (n >= 1) {
// sumofnnatural(n - 1);
// [Link](n + " ");
// }
// }
//}
//finding the missing number using java
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int size = [Link]() ;
// int[] a = new int[size];
// for (int i = 0; i < [Link]; i++) {
// a[i] = [Link]();
// }
// int n=[Link]+1;
// int expectedsum = (n * (n + 1)) / 2;
// int actualsum = 0;
// for (int i = 0; i < size; i++) {
// actualsum += a[i];
// }
// int missingnumber = expectedsum - actualsum;
// [Link](missingnumber);
// }
//}
// number of stairs he can climb to reach the final stair.
//import [Link];
//public class codes100{
// public static void main(String[] args) {
// Scanner scanner = new Scanner([Link]);
// int T = [Link]();
// for (int i = 0; i < T; i++) {
// int X = [Link]();
// int Y = [Link]();
// int ySteps = X / Y;
// int remainingSteps = X % Y;
// int totalMoves = ySteps + remainingSteps;
// [Link](totalMoves);
// }
// [Link]();
// }
//}
//generae the paranthesis using recursion-we can use any brackets like (),{}.[] any one of
them we can use
//import [Link];
//public class codes100{
// public static void main(String[] args) {
// Scanner scanner = new Scanner([Link]);
// int n = [Link]();
// char[] a = new char[n * 2];
// generateparenthesis(a,n,0,0,0);
// }
// static void generateparenthesis(char[] a,int n,int i,int o ,int c){
// if(i==[Link]) {
// [Link](a);
// return;
// }
// if(o<n) {
// a[i] = '(';
// generateparenthesis(a, n, i + 1, o + 1, c);
// }
// if(c<o) {
// a[i] = ')';
// generateparenthesis(a, n, i + 1, o, c + 1);
// }
// }
//}
//find the subsequences of the given string using recursion
//import [Link];
//import [Link];
//public class codes100{
// public static void main(String[] args) {
// Scanner scanner = new Scanner([Link]);
// String s = [Link]();
// subsequences(s,"");
// [Link](result);
// }
// static ArrayList<String> result=new ArrayList<String>();
// static void subsequences(String s,String ans){
// if([Link]()==0){
// [Link](ans);
// return;
// }
// subsequences([Link](1),ans+[Link](0));
// subsequences([Link](1),ans);
// }
//}
// letter combinations in the phone using the recursion
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// String a=[Link]();
// possiblewords(a, "");
// }
//
// static String[] keypad = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
// static void possiblewords(String a, String ans) {
// if ([Link]() == 0) {
// [Link](ans);
// return;
// }
// String key = keypad[[Link](0) - 48]; //mainly used to convert the integer string into
decimal
// for (int i = 0; i < [Link](); i++) {
// possiblewords([Link](1), ans + [Link](i));
// }
// }
//}
/*span of the array
span=maximum element-minimum element
*/
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// int n = [Link]();
// int[] a = new int[n];
// for (int i = 0; i < [Link]; i++) {
// a[i] = [Link]();
// }
// int ans1 = a[0];
// for (int i = 0; i < n; i++) {
// if (ans1 < a[i]) {
// ans1 = a[i];
// }
// }
// int ans = a[0];
// for (int i = 0; i < n; i++) {
// if (ans > a[i]) {
// ans = a[i];
// }
// }
// int span = ans1 - ans;
// [Link](span);
// }
//}
/*program for rotated sorted array-rotated sorted array means if we have array
like{1,2,3,4,5,6,7}
if we hae to rotate from index 3 so it looks like {4,5,6,7,1,2,3}*/
//public class codes100 {
// public static void main(String[] args) {
// int[] a = {4, 5, 6, 7, 1, 2, 3};
// int target = 1;
// [Link](rotatedsorted(a, target));
// }
//
// static int rotatedsorted(int[] a, int target) {
// int start = 0;
// int end = [Link] - 1;
// while (start <= end) {
// int mid = start + (end - start) / 2;
// if (target == a[mid]) {
// return mid;
// }
// if (a[start] <= a[mid]) {
// if (target < a[mid] && target >= a[start]) {
// end = mid - 1;
// } else {
// start = mid + 1;
// }
// }
// else {
// if (target > a[mid] && target <= a[end]) {
// start = mid + 1;
// } else {
// end = mid - 1;
// }
// }
// }
// return -1;
// }
//}
/*median of two sorted arrays with the complexity of 0(m+n);
median for odd elements=no of elements/2;
median for even elements=sum of middle terms/2
*/
//import [Link].*;
//public class codes100{
// public static void main(String[] args) {
// int[] arr1={1,3,8,17};
// int[] arr2={5,6,7,19,21,23};
// [Link](mergesorted(arr1,arr2));
// }
// static float mergesorted(int[] arr1,int[] arr2) {
// int i = 0, j = 0, k = 0;
// int[] mix = new int[[Link] + [Link]];
// while (i < [Link] && j < [Link]) {
// if (arr1[i] < arr2[j]) {
// mix[k] = arr1[i];
// i++;
// k++;
// } else {
// mix[k] = arr2[j];
// j++;
// k++;
// }
// }
// while (i < [Link]) {
// mix[k] = arr1[i];
// i++;
// k++;
// }
// while (j < [Link]) {
// mix[k] = arr2[j];
// j++;
// k++;
// }
// if ([Link] % 2 == 0) {
// int mid = [Link] / 2;
// return (float) (mix[mid] + mix[mid - 1]) / 2;
// } else {
// int mid = [Link] / 2;
// return mix[mid];
// }
// }
//}
//rotate the array using java-0(n*k)(it's not an efficient approach)
//import [Link].*;
//public class codes100{
// public static void main(String[] args) {
// int[] a = {1, 2, 3, 4, 5};
// rotatektimes(a,3);
// for (int i = 0; i < [Link]; i++) {
// [Link](a[i] + " ");
// }
// }
// static void rotatearray(int[] a) {
// int ans = a[0];
// for (int i = 1; i < [Link]; i++) {
// a[i - 1] = a[i];
// }
// a[[Link] - 1] = ans;
// }
// static void rotatektimes(int[] a,int k){
// k=k%[Link];
// if(k<0){
// k=k+[Link];
// }
// for(int i=1;i<=k;i++){
// rotatearray(a);
// }
// }
//}
//rotate an array with efficient approach-0(n)
//import [Link].*;
//public class codes100{
// public static void main(String[] args) {
// int[] a = {1, 2, 3, 4, 5};
// rotatektimes(a,9);
// for (int i = 0; i < [Link]; i++) {
// [Link](a[i] + " ");
// }
// }
// static void reverseanarray(int[] a,int start,int end){
// while(start<end){
// int temp=a[start];
// a[start]=a[end];
// a[end]=temp;
// start++;
// end--;
// }
// }
// static void rotatektimes(int[] a,int k) {
// k = k % [Link];
// if (k < 0) {
// k = k + [Link];
// }
// reverseanarray(a, 0, k - 1);
// reverseanarray(a, k, [Link] - 1);
// reverseanarray(a, 0, [Link] - 1);
// }
//}
//move all zeros to the end of the array using two pointer technique
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// int[] a = {2, 1, 0, 0, 4, 0, 5};
// zeros(a);
// for(int i=0;i<[Link];i++){
// [Link](a[i]+" ");
// }
// }
// static void zeros(int[] a) {
// if ([Link] == 0 || [Link] == 1) {
// return;
// } else {
// int nz = 0, z = 0;
// while (nz < [Link]) {
// if (a[nz] != 0) {
// int temp = a[nz]; //nz is the non zero and z is the zero
// a[nz] = a[z];
// a[z] = temp;
// nz++;
// z++;
// } else {
// nz++;
// }
// }
// }
// }
//}
//finding the maximum subarray in the array
//subarray-a small part of the array
//import [Link].*;
//public class codes100 {
// public static void main(String[] args) {
// int[] a = {1, 2, 3, 4, 5};
// subarray(a);
// }
// static void subarray(int[] a) {
// for (int i = 0; i < [Link]; i++) {
// for (int j = i; j < [Link]; j++) {
// for (int k = i; k<= j; k++) {
// [Link](a[k] + " ");
// }
// [Link]();
// }
// }
// }
//}
//import [Link];
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// int count = 0;
// for (int i = 0; i < [Link](); i++) {
// count++;
// }
// [Link](count);
// }
//}
//palindrome strings
//import [Link];
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// char[] arr = [Link]();
// [Link](palindrome(arr));
// }
//
// static boolean palindrome(char[] arr) {
// int left = 0;
// int right = [Link] - 1;
// while (left < right) {
// if (arr[left] != arr[right]) {
// return false;
// } else {
// left++;
// right--;
// }
// }
// return true;
// }
//}
//anagrams
//import [Link];
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String str1 = [Link](); // eat
// String str2 = [Link](); // ate
// if ([Link]() == [Link]()) {
// char char1[] = [Link]();
// char char2[] = [Link]();
// [Link](char1);
// [Link](char2);
// boolean result = [Link](char1, char2);
// if (result) {
// [Link]("Anagrams");
// } else {
// [Link]("Not Anagrams");
// }
// } else {
// [Link]("Not Anagram");
//
// }
// }
//}
//java program for the checking whether the given character is uppercase or lowercase
//import [Link];
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// char ch = [Link]().charAt(0);
// if (ch >='A' && ch <= 'Z') {
// [Link](1);
// } else if (ch >= 'a' && ch <= 'z') {
// [Link](0);
// } else {
// [Link](-1);
// }
// }
//}
// calculate the number of vowels and consonants in the given string
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String str = [Link]();
// int vowelcount = 0, consonantcount = 0,whitespaces=0;
// for (int i = 0; i < [Link](); i++) {
// char ch=[Link](i);
// if (ch== 'a'|| ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') {
// vowelcount++;
// }
// else if(ch==' '){
// whitespaces++;
// }
// else {
// consonantcount++;
// }
// }
// [Link]("number of vowels "+vowelcount);
// [Link]("number of consonants "+consonantcount);
// [Link]("number of white spaces "+whitespaces);
// }
//}
//find the ascii value of the character-using type casting we can achieve the following code
//import [Link];
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// char ch = [Link]().charAt(0);
// int result=ch;
// [Link](result); //ascii value of lowercase letter starts from 97 and
uppercase starts from 65
// }
//}
//remove the vowels from the given string
//import [Link];
//import [Link].*;
//public class Stringproblems{
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// String str=[Link]();
// String result=[Link]("[aeiouAEIOU]","");
// [Link](result);
// }
//}
//remove the white spaces from the given string
//import [Link];
//import [Link].*;
//public class Stringproblems{
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// String str=[Link]();
// String result=[Link](" ","");
// [Link](result);
// }
//}
//program to check whether the given character is alphabet or not
//import [Link];
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// char s = [Link]().charAt(0);
// if (s >= 'A' && s <= 'Z' || s >= 'a' && s <= 'z') {
// [Link](s + " is a alphabet");
// } else {
// [Link](s + " is not an alphabet");
// }
// }
//}
//toggle each character in the string like character is uppercase change it to lowercase
viceversa
//import [Link];
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String str=[Link]();
// String s1="";
// for(int i=0;i<[Link]();i++){
// if([Link]([Link](i))) {
// s1 = s1 + [Link]([Link](i));
// }
// else{
// s1 = s1 + [Link]([Link](i));
// }
// }
// [Link](s1);
// }
//}
//remove the characters in the string except the alphabets
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// String res=[Link]("[^a-zA-Z]", "");
// [Link](res);
// }
//}
//Remove the braces from the given algebraic expression
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// String res=[Link]("[{}()]", "");
// [Link](res);
// }
//}
//count the sum of the digits in the given string
//import [Link].*;
//public class Stringproblems{
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// String s=[Link]();
// int sum=0;
// for(int i=0;i<[Link]();i++) {
// if ([Link](i)>='0'&&[Link](i)<='9') {
// sum += ([Link](i)-'0');
// }
// }
// [Link](sum);
// }
//}
//captialize the first and last character of the stirng
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// String s1="";
// s1 = s1+[Link]([Link](0))+[Link](1,[Link]()-
1)+[Link]([Link]([Link]() - 1));
// [Link](s1);
// }
//}
//count the frequency of characters in the given string
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// char[] arr = [Link]();
// int[] freq = new int[256];
// for (int i = 0; i < [Link]; i++) {
// freq[arr[i]]++;
// }
// for (int i = 0; i < 256; i++) {
// if (freq[i] > 0) {
// [Link]((char)i+ " is " + freq[i]);
// }
// }
// }
//}
//find the first non repeated character in the given string
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// int[] count = new int[256];
// for (int i = 0; i < [Link](); i++) {
// count[[Link](i)]++;
// }
// for (int i = 0; i < [Link](); i++) {
// if (count[[Link](i)] == 1) {
// [Link]("the first non repeated character " + [Link](i));
// return;
// }
// }
// }
//}
//replace the substring with another substring
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// String oldstring = [Link]();
// String newstring = [Link]();
// String result = [Link](oldstring, newstring);
// [Link](result);
// }
//}
// replace the word in the given string by another word
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// String oldstring = [Link]();
// s = [Link](oldstring,"");
// s=[Link]();
// [Link](s);
// }
//}
//java program to print the even number of the characters
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// for (int i = 0; i < [Link](); i++) {
// if (i % 2 == 0) {
// [Link]([Link](i));
// }
// }
// }
//}
//java program to print unique characters
//import [Link].*;
//public class Stringproblems{
// public static void main(String[] args) {
// Scanner sc=new Scanner([Link]);
// String s=[Link]();
// char[] arr=[Link]();
// int[] count=new int[256];
// for(int i=0;i<[Link];i++) {
// count[arr[i]]++;
// }
// for(int i=0;i<256;i++){
// if(count[i]==1) {
// [Link]((char)i);
// }
// }
// }
//}
//program to print all the permutations of the given string
//import [Link].*;
//public class Stringproblems{
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// String ans ="";
// permute(s,ans);
// }
// static void permute(String s,String ans){
// if([Link]()==0) {
// [Link](ans);
// }
// else{
// for(int i=0;i<[Link]();i++){
// String rem=[Link](0,i)+[Link](i+1);
// permute(rem,ans+[Link](i));
// }
// }
// }
//}
//pangram strings in java
//import [Link].*;
//public class Stringproblems {
// public static void main(String[] args) {
// Scanner sc = new Scanner([Link]);
// String s = [Link]();
// [Link](pangrams(s));
// }
//
// static boolean pangrams(String s) {
// s = [Link]();
// Set<Character> val = new HashSet<>();
// for (char c : [Link]()) {
// if (c >= 'a' && c <= 'z') {
// [Link](c);
// }
// }
// return [Link]() == 26;
// }
//}
/*convert the string into integer-parseint method only
accepts the string with integer values if we use the character string then it will
throw the number format exception in order ti handle that exception we have to use the try
and catch block keywords that are used in the ecxception handlikng
*/
public class Stringproblems {
public static void main(String[] args) {
String s = "1798";
int result = [Link](s);
[Link](s);
}
}
//

You might also like