Kanha
BAN USER- -2of 2 votes
AnswersMake a JAVA program for an array of classes.
- Kanha in United States
class should have 4 or 5 attribute and Array should contain 10 data which all have that 4 or 5 attribute of class. And Retrieve each attribute from all data. (Like Array of structure in C).| Report Duplicate | Flag | PURGE
Java
public class ReplaceSubString{
static String s = "kanha is a good boy & he is the best";
static int count,i;
static char[] ch;
static char[]ch1 = new char[100];
static void replace(String ss,String sou,String dest)
{
ch =s.toCharArray();
int jj=0;
for(int j =0;j<ch.length;j++)
{
ch1[jj++]=ch[j];
count =0;
i=0;
if(sou.charAt(i)==ch[j])
{
count++;
int jjj=j;
while(i<sou.length()-1)
{
if(sou.charAt(++i)==ch[++jjj])
count++;
}
if(count == sou.length())
{
int kk=0;
j=jjj;
int ptr = --jj;
for(int iii=ptr;iii<ptr+dest.length();iii++)
{
ch1[iii] = dest.charAt(kk++);
jj++;
}
}
}
}
}
public static void main(String[] args) throws Exception
{
replace(s,"kanha","kanhaiya");
for(char chh:ch1)
System.out.print(chh);
}
}
public class SnakeSequence{
static int[][]arr ={{1,3,2,6,8},{-9,7,1,-1,2},{1,5,0,1,9}};
static boolean bip=true;
static boolean bis=true;
static boolean bjp=true;
static boolean bjs=true;
static void snake(int i, int j)
{
String s = "";
if(bip && i < arr.length-1 && Math.abs(arr[i][j] - arr[i+1][j]) == 1 )
{
s =s+arr[i][j];
System.out.println(s);
bis=false;
bip=true;
bjp=true;
bjs=true;
snake(i+1,j);
}
if ( bis && Math.abs(arr[i][j] - arr[Math.abs(i-1)][j]) == 1)
{
s =s+arr[i][j];
System.out.println(s);
bip=false;
bis=true;
bjp=true;
bjs=true;
snake(Math.abs(i-1),j);
}
if (bjp && j<4 && Math.abs(arr[i][j] - arr[i][j+1]) == 1)
{
s =s+arr[i][j];
System.out.println(s);
bjs = false;
bip=true;
bis=true;
bjp=true;
snake(i,j+1);
}
if ( bjs && Math.abs(arr[i][j] - arr[i+1][Math.abs(j-1)]) == 1)
{
s =s+arr[i][j];
System.out.println(s);
bjp =false;
bip=true;
bis=true;
bjs=true;
snake(i,Math.abs(j-1));
}
else
{
if(i==0&&j==0)
{
snake(i,j+1);
}
else
{System.out.println(arr[i][j]);
System.exit(0);
}
}
}
public static void main(String[] args) throws Exception
{
snake(0,0);
}
}
public class SubstringAddtion {
public static void main(String[] args) throws Exception
{
int [] arr = {1,7,6,3,5,8,9};
int n=16;
for(int i=0,j=0;i<arr.length-1;j++,i++)
{
String s="";
int chk=arr[i];
s=s+arr[i];
while(i<arr.length-1 && chk < n)
{
chk =chk+arr[i+1];
s= s+arr[i+1];
i++;
}
i=j;
if(chk == n)
{
System.out.println(s);
break;
}
}
System.out.println("Substring not found");
}
}
public class LookAndSay{
public static void main(String[] args) throws Exception
{
String s = "1";
String ss = "";
for(int j = 0;j<10;j++)
{
s=s+"0";
for(int i=0;i<s.length()-1;i++)
{
count =1;
while(s.charAt(i)==s.charAt(i+1))
{
count++;
i++;
}
ss = ss+count+s.charAt(i);
}
System.out.print(ss + " ");
s = ss;
ss="";
}
}
}
public class Test {
int a[]={1,2,3,4,5,6};
final int C=6;
void chk()
{
System.out.print("{");
for(int i=0;i<a.length;i++)
{
for(int j=i;j<a.length;j++)
{
if ((a[i]+a[j])== C)
System.out.print("{"+a[i]+","+a[j]+"},");
}
if (a[i]==C)
System.out.print("{"+a[i]+"}}");
}
}
public static void main(String args[]){
Test obj = new Test();
obj.chk();
}
}
- Kanha July 22, 2015