https://amzn.to/2JBbwlo New Arrival on Amazon buy now...
Mostly asked programming Questions in Written test for Developers
Q WAP to print a triangle of * pattern.
public class StarTr
{
public static void main(String arg[])
{
int i,j,k;
for(i=1; i<=5; i++)
{
for(j=4; j>=i; j--)
{
System.out.print(" ");
}
for(k=1; k<=(2*i-1); k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print pattern of star in given format.
*
***
*****
*******
*********
public class StarTr1
{
public static void main(String arg[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=4;j>=i;j--)
{
System.out.print("");
}
for(k=1;k<=(2*i-1);k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
OUTPUT
Q WAP to print to pattern of * in opposite of triangle.
public class StarPt2 {
public static void main(String arg[])
{
int i,j,k;
for (i=5;i>=1;i--)
{
for (j=5;j>i;j--)
{
System.out.print(" ");
}
for (k=1;k<(i*2); k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print the following pattern
*
**
***
****
*****
public class StarTr3 {
public static void main(String arg[])
{
int i,j;
for (i=1;i<=6;i++)
{
for (j=1;j<i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print the right angle of * pattern at right side.
public class StarTr4 {
public static void main(String arg[])
{
int i,j,k;
for (i=5;i>=1;i--)
for (j=1;j<i;j++)
{
System.out.print(" ");
}
for (k=5;k>=i; k--)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print following pattern of *.
public class StarTr4 {
public static void main(String arg[])
{
int i,j,k;
for (i=5;i>=1;i--)
{
for (j=1;j<i;j++)
{
System.out.print(" ");
}
for (k=5;k>=1; k--)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print *pattern .
public class StarTr5
{
public static void main(String arg[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
OUTPUT
Q WAP to print following pattern of*.
public class StarPt1 {
public static void main(String arg[])
{
int i,j,k;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
System.out.print(" ");
}
for(k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q. Write a program to print "*" in Diamond Shape.
public class StarPr {
public static void main(String arg[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
System.out.print(" ");
}
for(k=1;k<(2*i);k++)
{
System.out.print("*");
}
System.out.println("");
}
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
{
System.out.print(" ");
}
for(k=1;k<(i*2);k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
Q WAP to print given number of rows of * pyramid.
import java.util.Scanner;
public class StarPatrn
{
public static void main(String arg[])
{
int i,j,k=0,rows;
Scanner sc= new Scanner(System.in);
System.out.print("Enter the number of rows to be print:");
rows=sc.nextInt();
for(i=1; i<=rows; i++)
{
for(j=(rows-1);j>=i;j--)
{
System.out.print(" ");
}
for(k=1;k<=(2*i-1);k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
NUMBER PATTERN
1.
public class NumberPt
{
public static void main(String arg[])
{
int i,j,n=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(n+" ");
n++;
}
System.out.println();
}
}
}
OUTPUT
2.
public class Numberpt1 {
public static void main(String arg[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
OUTPUT
3.
public class NumberPt
{
public static void main(String arg[])
{
int i,j,n=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(n+" ");
}
n++;
System.out.println();
}
}
}
4.
public class NumberPt3
{
public static void main(String arg[])
{
int i,j;
for ( i=1;i<=5;i++)
{
for (j=1;j<=i;j++)
{
if (j%2==0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
System.out.println();
}
}
}
OUTPUT:
5.
public class NumPtr4
{
public static void main(String arg[])
{
int i,j;
for (i=1;i<=6;i++)
{
for(j=i;j>=1;j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
OUTPUT
6.
public class NumPt6
{
public static void main(String arg[])
{
int i,j;
for (i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
for (j=i-1;j>=1;j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
OUTPUT
Q1. Write a program to Check whether two strings are Anagram or not?
// here we import the package
import java.util.*;
// creating class
public class AnagramCh {
// creating method
static void isAnagram(String str1,String str3)
{
String s1= str1.replaceAll("\\s","");
String s3= str3.replaceAll("\\s","");
boolean status= true;
if (s1.length()!=s3.length())
{
status= false;
}
else
{
char[] ArrS1=s1.toLowerCase().toCharArray();
char[] ArrS3=s3.toLowerCase().toCharArray();
Arrays.sort(ArrS1);
Arrays.sort(ArrS3);
status=Arrays.equals(ArrS1, ArrS3);
}
if (status)
{
System.out.println(s1 +"and" +s3+ "Strings are anagram");
}
else
{
System.out.println(s1 +"and" +s3+ "are not anagram");
}
}
// creating main method
public static void main(String arg[])
{
isAnagram("Keep", "peek");
isAnagram("Mother In Law", "Hitler Woman");
}
}
OUTPUT
Mostly asked programming Questions in Written test for Developers
Patterns
public class StarTr
{
public static void main(String arg[])
{
int i,j,k;
for(i=1; i<=5; i++)
{
for(j=4; j>=i; j--)
{
System.out.print(" ");
}
for(k=1; k<=(2*i-1); k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
*
***
*****
*******
*********
public class StarTr1
{
public static void main(String arg[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=4;j>=i;j--)
{
System.out.print("");
}
for(k=1;k<=(2*i-1);k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
OUTPUT
Q WAP to print to pattern of * in opposite of triangle.
public class StarPt2 {
public static void main(String arg[])
{
int i,j,k;
for (i=5;i>=1;i--)
{
for (j=5;j>i;j--)
{
System.out.print(" ");
}
for (k=1;k<(i*2); k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print the following pattern
*
**
***
****
*****
public class StarTr3 {
public static void main(String arg[])
{
int i,j;
for (i=1;i<=6;i++)
{
for (j=1;j<i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print the right angle of * pattern at right side.
public class StarTr4 {
public static void main(String arg[])
{
int i,j,k;
for (i=5;i>=1;i--)
for (j=1;j<i;j++)
{
System.out.print(" ");
}
for (k=5;k>=i; k--)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q WAP to print following pattern of *.
public class StarTr4 {
public static void main(String arg[])
{
int i,j,k;
for (i=5;i>=1;i--)
{
for (j=1;j<i;j++)
{
System.out.print(" ");
}
for (k=5;k>=1; k--)
{
System.out.print("*");
}
System.out.println();
}
}
}
Q WAP to print *pattern .
public class StarTr5
{
public static void main(String arg[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
OUTPUT
Q WAP to print following pattern of*.
public class StarPt1 {
public static void main(String arg[])
{
int i,j,k;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
System.out.print(" ");
}
for(k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
Q. Write a program to print "*" in Diamond Shape.
public class StarPr {
public static void main(String arg[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
System.out.print(" ");
}
for(k=1;k<(2*i);k++)
{
System.out.print("*");
}
System.out.println("");
}
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
{
System.out.print(" ");
}
for(k=1;k<(i*2);k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
Q WAP to print given number of rows of * pyramid.
import java.util.Scanner;
public class StarPatrn
{
public static void main(String arg[])
{
int i,j,k=0,rows;
Scanner sc= new Scanner(System.in);
System.out.print("Enter the number of rows to be print:");
rows=sc.nextInt();
for(i=1; i<=rows; i++)
{
for(j=(rows-1);j>=i;j--)
{
System.out.print(" ");
}
for(k=1;k<=(2*i-1);k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
OUTPUT
NUMBER PATTERN
1.
public class NumberPt
{
public static void main(String arg[])
{
int i,j,n=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(n+" ");
n++;
}
System.out.println();
}
}
}
OUTPUT
2.
public class Numberpt1 {
public static void main(String arg[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
OUTPUT
3.
public class NumberPt
{
public static void main(String arg[])
{
int i,j,n=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(n+" ");
}
n++;
System.out.println();
}
}
}
OUTPUT
4.
public class NumberPt3
{
public static void main(String arg[])
{
int i,j;
for ( i=1;i<=5;i++)
{
for (j=1;j<=i;j++)
{
if (j%2==0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
System.out.println();
}
}
}
OUTPUT:
5.
public class NumPtr4
{
public static void main(String arg[])
{
int i,j;
for (i=1;i<=6;i++)
{
for(j=i;j>=1;j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
OUTPUT
6.
public class NumPt6
{
public static void main(String arg[])
{
int i,j;
for (i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
for (j=i-1;j>=1;j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
OUTPUT
Q1. Write a program to Check whether two strings are Anagram or not?
// here we import the package
import java.util.*;
// creating class
public class AnagramCh {
// creating method
static void isAnagram(String str1,String str3)
{
String s1= str1.replaceAll("\\s","");
String s3= str3.replaceAll("\\s","");
boolean status= true;
if (s1.length()!=s3.length())
{
status= false;
}
else
{
char[] ArrS1=s1.toLowerCase().toCharArray();
char[] ArrS3=s3.toLowerCase().toCharArray();
Arrays.sort(ArrS1);
Arrays.sort(ArrS3);
status=Arrays.equals(ArrS1, ArrS3);
}
if (status)
{
System.out.println(s1 +"and" +s3+ "Strings are anagram");
}
else
{
System.out.println(s1 +"and" +s3+ "are not anagram");
}
}
// creating main method
public static void main(String arg[])
{
isAnagram("Keep", "peek");
isAnagram("Mother In Law", "Hitler Woman");
}
}
OUTPUT
No comments:
Post a Comment