-
Do you mean theoretical questions or programming based questions?
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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?
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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[]?
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
Q. Write a program to implement shallow copy and deep copy
can you please explain about this program?
Are you sure? This action cannot be undone.
-
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
.
Are you sure? This action cannot be undone.
-
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 😀
Are you sure? This action cannot be undone.
-
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?
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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. 😉
Are you sure? This action cannot be undone.
-
@akd Thanks for explanation
@mohit hm i will give it a try
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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...??
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
varsha can you please quote the example.??
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
Thank you varsha for this example. 😀
Are you sure? This action cannot be undone.
-
vinci
Member •
Jan 16, 2012
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
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
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?
Are you sure? This action cannot be undone.
-
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);
}
}
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
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);
}
}
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
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
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
Write an optimized program to find the largest and second largest no in an array of numbers without using sorting.
Are you sure? This action cannot be undone.
-
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 ??
Are you sure? This action cannot be undone.
-
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.
Are you sure? This action cannot be undone.
-
what is output of this program and please explain in detail..
#include<stdio.h>
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);
}
Are you sure? This action cannot be undone.
-
public class triangle {
public static void main(String[] args)
{
int i=0,count=0;
int num=1;
while(num<6)
{
for(i=0;i<num;i++)
{
System.out.print(num-(count-i)+" ");
}
num++; count++;
System.out.println();
}
}
Are you sure? This action cannot be undone.