Collection of programming questions in java....?

hello friend's,
I think during exam time we all need the collection of the questions that cover all the topics of the programming language.
Not only during exam time it will also helps you to revise the entire subject.
I know most of our CEan's have some collection of programs which cover all the syllabus.
.
I requested all the CEan's to post your collection of programming questions in java which cover some sections.

Replies

  • Manish Goyal
    Manish Goyal
    Do you mean theoretical questions or programming based questions?
  • Morningdot Hablu
    Morningdot Hablu
    Not theoretical....post only your programming question collections....So that all our CEan's can give a try to it.
    You have to post the questions that cover the whole concepts of a particular topic.
  • Ankita Katdare
    Ankita Katdare
    Read the following program:

    public class test {
    public static void main(String [] args) {
    int x = 3;
    int y = 1;
    if (x = y)
    System.out.println("Not equal");
    else
    System.out.println("Equal");
    }
    }

    What is the result?
  • Ankita Katdare
    Ankita Katdare
    Write java application program for generating 4 threads to do the following operations.
    (i) getting n numbers
    (ii) printing even numbers
    (iii) printing odd numbers
    (iv) printing average of a numbers.
  • Ankita Katdare
    Ankita Katdare
    Q. Write a java application to get n numbers and print them in the order using Heap sort procedure.

    Q. Write a program to implement shallow copy and deep copy.

    Q. Assume you have an array list with 7 objects in it. And there is an int[] as:

    int[] intArray = new int[3];
    intArray[0] = 2;
    intArray[1] = 4;
    intArray[2] = 6;
    How do you go about deleting the objects from ArrayList based on the values in int[]?
  • Ankita Katdare
    Ankita Katdare
    Q. Can main() of one program in Java be invoked in another Java Program's main()? Explain with example.

    Q. Write a program in Java to give the output as follows:

    1
    1 2
    1 2 3
    1 2 3 4

    and

    1
    2 3
    4 5 6
    7 8 9 10
  • Manish Goyal
    Manish Goyal
    Q. Write a program to implement shallow copy and deep copy
    can you please explain about this program?
  • Morningdot Hablu
    Morningdot Hablu
    Display programs...

    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    ....
    1 1 1 1 1
    2 2 2 2 2
    3 3 3 3 3
    4 4 4 4 4
    5 5 5 5 5
    ......
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    ......
    1
    1 1
    1 1 1
    1 1 1 1
    1 1 1 1 1
    ......
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    .......
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
    .......
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    .........
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    .........
    ............1
    .........1 2 1
    ......1 2 3 2 1
    ...1 2 3 4 3 2 1
    1 2 3 4 5 4 3 2 1
    ...........

    ............1
    .........1 2 1
    ......1 2 3 2 1
    ...1 2 3 4 3 2 1
    1 2 3 4 5 4 3 2 1
    ...1 2 3 4 3 2 1
    ......1 2 3 2 1
    .........1 2 1
    ............1
    .
  • Manish Goyal
    Manish Goyal
    AbraKaDabra
    Q. Write a program in Java to give the output as follows:

    1
    1 2
    1 2 3
    1 2 3 4

    and

    1
    2 3
    4 5 6
    7 8 9 10
    class test {
    public static void main(String [] args) {
    int n=1;
    for(int i=1;i<5;i++)
    {
    for(int j=1;j<=i;j++)
    {
    System.out.print((n++)+(" "));
    }
    System.out.println();
    }
    }
    }
    class test {
    public static void main(String [] args) {
    for(int i=1;i<5;i++)
    {
    for(int j=1;j<=i;j++)
    {
    System.out.print(j+" ");
    }
    System.out.println();
    }
    }
    }
    PS:-I love these kinds of program since the day i fell in love with programming 😀
  • Manish Goyal
    Manish Goyal
    mohit007kumar00
    Display programs...

    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    ....
    1 1 1 1 1
    2 2 2 2 2
    3 3 3 3 3
    4 4 4 4 4
    5 5 5 5 5
    ......
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    ......
    1
    1 1
    1 1 1
    1 1 1 1
    1 1 1 1 1
    ......
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    .......
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
    .......
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    5 4 3 2 1
    .........
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    .........
    1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1
    1 2 3 4 5 4 3 2 1
    ...........

    1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1
    1 2 3 4 5 4 3 2 1
    1 2 3 4 3 2 1
    1 2 3 2 1
    1 2 1
    1
    .
    Do you want to display this output through a single program?
  • Morningdot Hablu
    Morningdot Hablu
    No It's the collection of programs.
    .
    But ya it's also a good idea to display all through a single program....give a try to it.
  • Ankita Katdare
    Ankita Katdare
    Re: Collection of programming questions in java?

    goyal420
    can you please explain about this program?
    Java provides a mechanism for creating copies of objects called cloning.
    There are basically two ways to make a copy of an object called shallow copy and deep copy.

    Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object.
    If any of the fields of the object are references to other objects, just the references are copied. Thus, if the object you are copying contains references to yet other objects, a shallow copy refers to the same sub objects.

    Deep copy
    is a complete duplicate copy of an object. If an object has references to other objects, complete new copies of those objects are also made.
    A deep copy generates a copy not only of the primitive values of the original object, but copies of all sub objects as well, all the way to the bottom. If you need a true, complete copy of the original object, then you will need to implement a full deep copy for the object.

    A little search on the internet will show you how to implement them using a Java program. 😉
  • Manish Goyal
    Manish Goyal
    @akd Thanks for explanation
    @mohit hm i will give it a try
  • Deepika Bansal
    Deepika Bansal
    AbraKaDabra
    Read the following program:

    public class test {
    public static void main(String [] args) {
    int x = 3;
    int y = 1;
    if (x = y)
    System.out.println("Not equal");
    else
    System.out.println("Equal");
    }
    }

    What is the result?

    The result is the compilation error in the code because if(x=y) is invalid in java. It should be if(x==y).
    Please correct me if i am wrong.
  • Deepika Bansal
    Deepika Bansal
    mohit007kumar00
    No It's the collection of programs.
    .
    But ya it's also a good idea to display all through a single program....give a try to it.
    it can be a menu based program. like what option the user chooses, accordingly the program will react.
    Is anyone having any other idea to implement these series in a single program code...??
  • Manish Goyal
    Manish Goyal
    yeah deepika this can be made

    i am thinking about a code through which you can create any pattern of your choice ,just input no and pattern will be ready
  • ritz53
    ritz53
    how to write programmme in java.. Odd number of position and even number of pos

    write a programme in java ...odd number of position and even no. of position ...
    eg: 5684
    odd add no: 5+8=13
    even add no.:6+4=10
  • Varsha0802
    Varsha0802
    AbraKaDabra;
    Q. Can main() of one program in Java be invoked in another Java Program's main()? Explain with example.
    Can it be done? Please explain. I haven't ever heard of this.
  • Varsha0802
    Varsha0802
    I got the answer. main() of one program in Java can be invoked in another Java Program's main(). It behaves just like any other method.
  • Deepika Bansal
    Deepika Bansal
    varsha can you please quote the example.??
  • Varsha0802
    Varsha0802
    Deepika consider the following example:

    class sum
    {      public static void main(String args[])
         {       String a[]={"5","7"};
                         int c;
                         c=calsum.main(a);
                         System.out.println("Sum:"+c);
              }
    }    
    [\code]
    
    [code]
    class calsum
    {        public static int main(String args[])
               {        int a,b;
                          a=Integer.parseInt(args[0]);
                          b=Integer.parseInt(args[1]);
                          return(a+b);
              }
    }
    [\code]
    
    When you will compile the program it will print the sum. Here main behaves as any other public static method.
  • Deepika Bansal
    Deepika Bansal
    Thank you varsha for this example. 😀
  • vinci
    vinci
    AbraKaDabra
    Read the following program:

    public class test {
    public static void main(String [] args) {
    int x = 3;
    int y = 1;
    if (x = y)
    System.out.println("Not equal");
    else
    System.out.println("Equal");
    }
    }

    What is the result?
    incompatible type in if
  • BoomBoom
    BoomBoom
    Hello people. i do have a question i am stuck with. can anyone help me with that?
    The Question is-
    Write a program to check whether a number entered by the user is a magic number or not.how do i do this program?
    i tried doing it with do-while loop but i guess my condition was wrong.
  • Anoop Kumar
    Anoop Kumar
    BoomBoom
    Hello people. i do have a question i am stuck with. can anyone help me with that?
    The Question is-
    Write a program to check whether a number entered by the user is a magic number or not.how do i do this program?
    i tried doing it with do-while loop but i guess my condition was wrong.
    could you please define what is exactly a magic number? not getting exact definition.
  • BoomBoom
    BoomBoom
    ianoop
    could you please define what is exactly a magic number? not getting exact definition.
    a number is said to be a magic number if the sum of it individual digit is 0.
    eg- 172=1+7+2=10=1+0=1
  • Anoop Kumar
    Anoop Kumar
    I did not get this, output of 172 is still 1.

    BTW Solution:
    you can get a while loop and do operation like
    while(yourNumber>0){

    tmp= yourNumber%10; /*modulo operation which returns reminder */
    /* add tmp in array */
    yourNumber=yourNumber/10;
    }

    add the all numbers of array and decide.
  • nareshkumar6539
    nareshkumar6539
    BoomBoom
    Hello people. i do have a question i am stuck with. can anyone help me with that?
    The Question is-
    Write a program to check whether a number entered by the user is a magic number or not.how do i do this program?
    i tried doing it with do-while loop but i guess my condition was wrong.
    package com.naresh;
    import java.util.Scanner;
    public class MagicNumber {
    staticintsum;
    static MagicNumber mn=new MagicNumber();
    publicstaticvoidmain(String args[])
    {
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter a number");
    int n=scan.nextInt();
    mn.addDigits(n);
    }//End of main()
    publicvoid addDigits(int n)
    {
    sum=0;
    while(n>0)
    {
    sum=sum+n%10;
    n=n/10;

    }
    mn.checkSum(sum);

    }//End of addDigits()
    publicvoid checkSum(int sum)
    {
    if(sum>=0&&sum<10)
    {
    if(sum==0)
    {
    System.out.println("Given number is magic number");
    System.exit(0);
    }
    else
    {
    System.out.println("Given number is not a magic number");
    System.exit(0);
    }
    }
    else
    mn.addDigits(sum);
    }//End of checkSum()

    }//End of the class
  • BoomBoom
    BoomBoom
    thank you people for helping me.
    now I am stuck with 2 questions-
    1).Write a program to check whether it is a unique number or not. A unique number is a number which has no leading 0 and no digit is repeated in it.
    i have done this program using string, but i am not getting that how do i do it without using String. so please can anyone help?

    and the other problem is-

    2) What is the problem in the following code that the loop is going on to infinity,i.e.,it's not stopping and not giving the correct output.

    import java.util.*;
    class Word_Scanner
    {
    public static void main(String args [])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter any String(word or sentence)");
    String s=sc.next();
    int c=0;
    while(sc.hasNext())
    {
    String ss=sc.next();
    System.out.println(ss);
    c++;
    }
    System.out.println("Number of words="+c);
    }
    }

    suppose-
    INPUT-MY NAME IS ROCKER
    OUTPUT-
    MY
    NAME
    IS
    ROCKER
    Number of words=4

    but it is not giving the number of words. So can anyone please explain why am i encountering this problem?
  • Anoop Kumar
    Anoop Kumar
    1) Change number into char array and match it.
    2) here is modified code
    import java.util.*;
     
    class Word_Scanner {
        public static void main(String args[]) {
            Scanner sc = new Scanner(System.in);
            System.out.println("Enter any String(word or sentence)");
            int c = 0;
            while (sc.hasNext()) {
                String ss = sc.next();
                System.out.println(ss);
                c++;
     
                if (sc.findInLine(" ") == null) {
                    sc.close();
                    break;
                }
            }
     
            System.out.println("Number of words=" + c);
        }
    }
    
  • Uzair Akmal
    Uzair Akmal
    Java program that will use a counting loop and ask the user for 10 integer values and print the multiplication of the odd numbers which are greater than 1 and less than or equal to 11.
  • BoomBoom
    BoomBoom
    Can,t we do it directly in the int datatype only without type casting it??
    and for the second one-
    but what is the problem if we use the line-
    String s=sc.nextLine();
    This line has no work in the program and using this line won't affect the program also, as we are not using the variable s anywhere, but still it is not showing the correct output. why? can you please explain
  • BoomBoom
    BoomBoom
    Uzair Akmal
    Java program that will use a counting loop and ask the user for 10 integer values and print the multiplication of the odd numbers which are greater than 1 and less than or equal to 11.

    import java.io.*;
    class odd
    {
    public static void main(String args [])throws IOException
    {
    InputStreamReader isr=new InputStreamReader(System.in);
    BufferedReader br=new BufferedReader(isr);
    System.out.println("Enter 10 integer values");
    int c=1;
    int p=1;
    while(c!=10)
    {
    c++;
    int n=Integer.parseInt(br.readLine());
    if(n%2!=0&&n>1&&n<=11)
    p=p*n;
    }
    System.out.println("Product of odd numbers >1 and <=11 ="+p);
    }
    }
  • BoomBoom
    BoomBoom
    ianoop
    1) Change number into char array and match it.
    2) here is modified code
    import java.util.*;
     
    class Word_Scanner {
        public static void main(String args[]) {
            Scanner sc = new Scanner(System.in);
            System.out.println("Enter any String(word or sentence)");
            int c = 0;
            while (sc.hasNext()) {
                String ss = sc.next();
                System.out.println(ss);
                c++;
     
                if (sc.findInLine(" ") == null) {
                    sc.close();
                    break;
                }
            }
     
            System.out.println("Number of words=" + c);
        }
    }
    

    Can,t we do it directly in the int datatype only without type casting it??
    and for the second one-
    but what is the problem if we use the line-
    String s=sc.nextLine();
    This line has no work in the program and using this line won't affect the program also, as we are not using the variable s anywhere, but still it is not showing the correct output. why? can you please explain sir
  • pawan.kumar123
    pawan.kumar123
    AbraKaDabra
    Read the following program:

    public class test {
    public static void main(String [] args) {
    int x = 3;
    int y = 1;
    if (x = y)
    System.out.println("Not equal");
    else
    System.out.println("Equal");
    }
    }

    What is the result?
    this program will not compile because if (x = y) in this x=y returns the new assigned value to x i.e. 1 which is an integer not a boolean resulting in compilation error
  • hare singh nayak
    hare singh nayak
    mohit007kumar00
    Not theoretical....post only your programming question collections....So that all our CEan's can give a try to it.
    You have to post the questions that cover the whole concepts of a particular topic.
  • Anoop Kumar
    Anoop Kumar
    BoomBoom
    Can,t we do it directly in the int datatype only without type casting it??
    and for the second one-
    but what is the problem if we use the line-
    String s=sc.nextLine();
    This line has no work in the program and using this line won't affect the program also, as we are not using the variable s anywhere, but still it is not showing the correct output. why? can you please explain sir
    you can do this using modulo operator. iterate with number%10 and put numbers into set to verify.
    you are using System.in that mean you program is reading in infinite loop.
  • sookie
    sookie
    Write an optimized program to find the largest and second largest no in an array of numbers without using sorting.
  • BoomBoom
    BoomBoom
    ianoop
    you can do this using modulo operator. iterate with number%10 and put numbers into set to verify.
    you are using System.in that mean you program is reading in infinite loop.
    Sorry but can you please elaborate on that point of my loop being infinite because i am using System.in ??
  • Anoop Kumar
    Anoop Kumar
    BoomBoom
    Sorry but can you please elaborate on that point of my loop being infinite because i am using System.in ??
    System.in will continue to read from command line as you have condition while(sc.hasNext)..
    there will always be next thing in case of any key stroke. and if there is no key stroke wait for it.
  • hare singh nayak
    hare singh nayak
    what is output of this program and please explain in detail..


    #include
    main()
    {
    int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
    int *p,*q;
    p=&a[2][2][2];
    *q=***a;
    printf("%d----%d",*p,*q);
    }
  • crystal m
    crystal m
    public class triangle {
    public static void main(String[] args)
    {
    int i=0,count=0;
    int num=1;
    while(num<6)
    {
    for(i=0;i {
    System.out.print(num-(count-i)+" ");
    }
    num++; count++;
    System.out.println();

    }
    }

You are reading an archived discussion.

Related Posts

Name: LUIS CABREJO *Engineering Trade: INFORMATION SYSTEMS Location: PERU and WASHINGTON DC *Occupation: INVESTIGATOR - WRITER Work Experience: RURAL TELECOMUNICATIONS SAT ENG - GOVERNMENT WORK *Hobbies & Interests: ANCIENT PERUVIAN...
Ok dear colleagues, it has been very hard to discuss with archeologist and anthropologists, but I always told them that NASCA LINES were not a UFO, or praying ritual paths,...
Armed to support today's flexible, varied enterprise architectures, Red Hat Enterprise Linux 6 provides a rock-solid foundation for every deployment—including virtualization and cloud computing. By incorporating software technologies developed by...
Facebook has predicted that its new messaging service will make phone numbers and email addresses obsolete. Source : Facebook says new messaging service will make email addresses obsolete - Telegraph...
Lamebook showcases some of the hilariously inept postings on Facebook, keeping user names anonymous. The site claims the use of the name “Lamebook” is within its First Amendement Rights and...