Doubts posted in WhatsApp(+91 62941 96364) on 21-6-2020 from a student from Kanpur:
Solutions:
Question 1:
class Pattern
{
static void main()
{
int i,j,l=10;
String s1="A B C D E ", s2="1 2 3 4 5 ",t;
for(i=1;i<=5;i++)
{
for(j=1;j<2 i="" j="" p="">
System.out.print(" ");
if(i%2!=0)
System.out.print(s1.substring(0,l)+s2.substring(0,l));
else
System.out.print(s2.substring(0,l)+s1.substring(0,l));
System.out.println();
l-=2;
}
}
}
Question 2:
class Series1
{
static void main()
{
int i,j;
char x;
String s1="",s2="",s3="",s4="";
for(i=1;i<=26-4;i+=4)//There are 26 alphabets
//grouped with 4 characters in each group
{
//form a group of 4 characters
s1="";
for(j=i;j<=3+i;j++)
{
x=(char)(j+64);
s1+=x;
}
System.out.print(s1+",");
//form a group of repeating chracters (2 times)
s2="";
for(j=i;j<=3+i;j++)
{
x=(char)(j+64);
s2=s2+x+x;
}
System.out.print(s2+",");
//reverse s2
s3="";
for(j=0;j
2>
s3=s2.charAt(j)+s3;
System.out.print(s3+",");
//reverse s1
s4="";
for(j=0;j
s4=s1.charAt(j)+s4;
System.out.print(s4+",");
}
}
}
Question 3:
class Series2
{
static void main()
{
int i,j;
String s="";
for(i=1;i<=26;i++)
{
s="";
for(j=1;j<=i;j++)
{
if(i%2!=0)
s=s+(char)(i+64);
else
s=s+(char)(i+96);
}
System.out.print(s);
}
}
}
No comments:
Post a Comment