Skip to main content

Posts

Showing posts from January, 2020

FIND THE NO OF SUBSTRINGS DIVISIBLE BY 7 --> INPUT -3567 OUTPUT-4 -->(35,56,567,7)

/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner input = new Scanner(System.in); String number = input.nextLine(); String sub; int length=number.length(); int i=0; for(int first=0;first<length;first++) { for(int second=first+1;second<=length;second++) { sub = number.substring(first,second); int a = Integer.parseInt(sub); if((a%7)==0) { i++; } } } System.out.println(i); } }

SWAP EACH CONSECUTIVE PAIRS UNTIL THERE IS NO PAIR and THEN REVERSE THE VOWELS ---> INPUT:-NAGIEM OUTPUT:-ENIGMA

/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*;a /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner input = new Scanner(System.in); String s = input.nextLine(); char[] sCharArray = s.toCharArray(); char[] newWordArray = new char[sCharArray.length]; char temp; int firstletter=0; int secondletter=1; int length = sCharArray.length; for(int i=0,n=length/2;i<n;i++) { temp= sCharArray[firstletter]; sCharArray[firstletter]=sCharArray[secondletter]; sCharArray[secondletter]=temp; firstletter=firstletter+2; secondletter=secondletter+2; } String news = new String(sCharArray); System.out.println(news); int j=0; for(int i=0,n=sCharArray.length;i<n;i++) { if(Character.toLowerCase(sCharArray[i])=='a'||Character.toLowe