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.
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 GoyalDo you mean theoretical questions or programming based questions?
-
Morningdot HabluNot 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 KatdareRead 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 KatdareWrite 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 KatdareQ. 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 KatdareQ. 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
Q. Write a program to implement shallow copy and deep copy
can you please explain about this program? -
Morningdot HabluDisplay 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 GoyalAbraKaDabraQ. 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 10class 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
Do you want to display this output through a single program?mohit007kumar00Display 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
. -
Morningdot HabluNo 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 KatdareRe: Collection of programming questions in java?
Java provides a mechanism for creating copies of objects called cloning.goyal420can you please explain about this program?
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@akd Thanks for explanation
@mohit hm i will give it a try -
Deepika BansalAbraKaDabraRead 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
it can be a menu based program. like what option the user chooses, accordingly the program will react.mohit007kumar00No 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.
Is anyone having any other idea to implement these series in a single program code...?? -
Manish Goyalyeah 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 -
ritz53how 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
Can it be done? Please explain. I haven't ever heard of this.AbraKaDabra;Q. Can main() of one program in Java be invoked in another Java Program's main()? Explain with example. -
Varsha0802I 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 Bansalvarsha can you please quote the example.??
-
Varsha0802Deepika 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 BansalThank you varsha for this example. 😀
-
vinci
incompatible type in ifAbraKaDabraRead 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? -
BoomBoomHello 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
could you please define what is exactly a magic number? not getting exact definition.BoomBoomHello 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. -
BoomBoom
a number is said to be a magic number if the sum of it individual digit is 0.ianoopcould you please define what is exactly a magic number? not getting exact definition.
eg- 172=1+7+2=10=1+0=1 -
Anoop KumarI 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
package com.naresh;BoomBoomHello 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.
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 -
BoomBoomthank 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 Kumar1) 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 AkmalJava 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.
-
BoomBoomCan,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 -
BoomBoomUzair AkmalJava 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);
}
} -
BoomBoomianoop1) 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
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 errorAbraKaDabraRead 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? -
hare singh nayakmohit007kumar00Not 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
you can do this using modulo operator. iterate with number%10 and put numbers into set to verify.BoomBoomCan,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 are using System.in that mean you program is reading in infinite loop. -
sookieWrite an optimized program to find the largest and second largest no in an array of numbers without using sorting.
-
BoomBoom
Sorry but can you please elaborate on that point of my loop being infinite because i am using System.in ??ianoopyou 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. -
Anoop Kumar
System.in will continue to read from command line as you have condition while(sc.hasNext)..BoomBoomSorry but can you please elaborate on that point of my loop being infinite because i am using System.in ??
there will always be next thing in case of any key stroke. and if there is no key stroke wait for it. -
hare singh nayakwhat 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 mpublic 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...