Not getting the result what I want in java by using array and string? -


input:-

agxgw 3 2 4 2 5 7 14 

output:-

yes no yes 

i answer “yes” or “no” using following rule: select 2 integers , b, if element @ position same element position b in non-ending chant. answer yes, otherwise no.

code:

import java.util.scanner;  public class gf {      /**      * @param args      */     public static void main(string[] args) {         // todo auto-generated method stub         scanner sc = new scanner(system.in);                 string k=sc.next();         int k1=k.length();         int a=sc.nextint();         (int =0; <a; i++) {             int b=sc.nextint();             int b1=b%k1;             int c=sc.nextint();             int c1=c%k1;             if(k.charat(b1)==k.charat(c1)) {                 system.out.println("yes");             } else {                 system.out.println("no");             }         }     } } 

once char b1 , c1. need find weather chars in string k = "agxgw" @ position b1 , c1 same or not. string k small integers b1 , c1 can bigger length.

so calculate mod of of string length b1 , c1 , compare if chars same or not.

for example:

mod can calculated % operator.

m1 = b1 % stringlength of k m2 = c1 % stringlength ok k 

now char m1 , m2 smaller stringlength of k compare if both same or not.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -