Java Basic Programs (Java Programming)
Java Basic Programs (Java Programming)
5.What is a variable?
6.Write a program that takes 5 numbers as input the program that will
take and then print the cumulative sum of the numbers?
9.#include<stdio.h>
int main()
{
1
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
int n=10;
int fun(int);
printf("%d",fun(n));
}
int fun(int n)
{
if(n>0)
return (n+fun(n-2));
else
return 0;
}
a)30
b)Error
c)10
d)15
10.#include<stdio.h>
int main()
{
char str1[] = {'s','o','m','e'};
char str2[] = {'s','o','m','e','\0'};
if(strcmp(str1,str2))
{
2
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
printf("Strings are not equal\n");
}
else
{
printf("Strings are equal\n");
}
}
a)Error
b)Strings are not equal
c)Strings are equal
d)compile error.
11.Write a program to print fibonacci numbers which has even digit in it.
12.Write a program to print prime digits of palindrome numbers between m and n.
13.Write a program to check reverse of a number is Strong number or not.
14.Write a program to print the perfect numbers which has only two digits in it.
15.#include<stdio.h>
int main()
{
const char *s="";
char str[] = "Hello";
s=str;
3
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
while (*s)
printf("%c",*s++);
return 0;
}
a)Error
b)H
c)Hello
dHel
16.#include<stdio.h>
int main()
{
int a[s]={1,3,6,7,0};
int *b;
b=&a[2];
printf("%d",b[-1]);
}
17.#include<stdio.h>
main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
4
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
printf("%d %d %d %d %d",i,j,k,l,m);
}
a)0 0 1 2
b)0 0 1 3 0
c)0 0 1 3 1
d)0 0 0 2 1
18.#include<stdio.h>
int main()
{
int i=32,j=0X20, k, l, m;
k=i|j;
l=i&j;
m=k*l;
printf("%d,%d,%d,%d,%d\n",i,j,k,l,m);
return 0;
}
19:What is a compiler?
20:Given
1.String #name = "jane Doe";
2.int Sage=24
3.Double_height=123.5;
4.double-temp=37.5;
5
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
Which two statements are true?
(choose two)
22.Features of java
23.Jvm means?
25. Write a program for swapping 2 numbers and write palindrome program for the
swapping numbers
6
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
31.Pallindrome program.
7
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1.class Test{
public static void main (String[] args)
{
int x=20;
String sup =(x<15)?"small": (x<22)?"tiny":"huge";
System.out.pritnln(sup);
}
a)small
b)tiny
c)huge
d)compilation fails
35.Write a program to print second largest digit and second smallest digit in a given
number.
36.Write a program to print even digit summation of 15 fibonacci numbers.
37.Write a program to check 10th perfect square first digit is prime or not.
38.Write a program to count number prime digits present in first 10 palindrome
numbers.
8
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
39.Write a program to print spy fibonacci numbers between m and n.
40.Write a program to print the palindrome numbers whose digits summation is 6
between m and n.
41.Write a program to print factorial of second largest digit of a number.
42.Write a program to find second smallest digit to the power of second largest digit of
a number.
43.What will be the output of the following
#define FUN(i,j) i##j
int main()
{
int val1=10;
int val2=20;
printf("%d\n",FUN(val1,2));
return 0;
}
44.What will be the output if you compile and execute the following c code?
void main(){
char *str="Hello World";
printf("%d".printf("%s",str));
a)11Hello World
b)Hello World10
c)Hello World11
d)10Hello World
9
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
45.How many loops are there in java?
1)Write a program to find how many ways can you arrange the number 521.
for ex: 123
321
213
132
231
312
o/p: 6
46) Write a program to print the numbers, whose sum of it's digits recursively
calculated till single digit
and that single digit should be 1 between m and n.
for ex: n=325
sumOfDigits1=3+2+5=10
sumOfDigits2=1+0=1.
47) WAPTP the numbers whose sum of its digit raised to the power of their respective
positions is equal to the number itself between i and j.
for ex: n=175.
n=1^1+7^2+5^3=175.
48)Write a program to print the numbers whose sum of squares of its digits calculated
till summation
should be equal to 1.
for ex : n=19
10
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1.
49)3 3 3 3 3
222
1
222
33333
50.What is singleton class?
51)Write a program to print the numbers after perfoming square it should be
palindrome number between m and n.
for example : n=11
square=n*n=11*11=121(121 is palindrome number).
53)Write a program to check 10th strong number's second largest digit is prime or not.
11
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
by selling this mango he buys another mango, for the next time he buys the number of
mango which is the sum
of the two previous purchases.
55) 1
121
12321
1234321
123454321
12345654321
1234567654321
56.What is a java?
12
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
if it is a ArmStrong number then check second largest digit of a given number is
perfect number or not.
63.Write a program to print even palindrome numbers between 1 to 1000 in
descending order.
64.Write a program to print 10 prime fibonacci numbers in descending order.
67.Print numbers
68.Fibonacci numbers
13
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
69.Write a program to print second largest prime digit in a given number.
70.Write a program to print even digit summation of 15 fibonacci numbers.
71.Write a program to check 10th perfect square number's first digit is sunny number
or not.
72.Write a program to count number of prime digits present in first 10 palindrome
numbers.
73.1
121
12321
1234321
123454321
12345654321
1234567654321
74.public class Metti{
public static void main(String[] args)
{
int x=5;
boolean b1 = true;
boolean b2 = false;
if((x==4)&&!b2)
System.out.println("1");
System.out.println("2");
14
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
if((b2=true)&&b1)
System.out.println("3");
}
}
75. WAP to print the numbers whose sum of it's digits powered with their respective
position
is equal to the original number between m and n.
76.WAPTP the numbers which has an even number of digits and the number can be
divided exactly into two parts from the middle.
After equally dividing the number, sum up the numbers and find the square of the
sum.
If we get the number itself as square then print that numbers between m and n.
78.WAP to chech summation of second largest digit and second smallest digit of a
number is Neon number or not.
Neon number: Summation of the digits of square of the given is equal to the original
number.
15
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
79.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
80.class Metti
{
public static void main (String[] args){
boolean bool = true;
if(bool==false)
{
System.out.println("a");
}
else if(bool)
{
System.out.println("b");
}
else if(!bool)
{
System.out.println("c");
}
else
16
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
{
System.out.println("d");
}
}
}
81.Program on fibonacci series.
17
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
int main()
{
int a,b;
a=sumdig(123);
b=sumdig(123);
printf("%d,%d\n",a,b);
return 0;
}
int sumdig(int n)
{
int s,d;
if(n!=0)
{
d=n%10;
n=n/10;
s=d+sumdig(n);
}
else
return 0;
return s;
}
a)4,4
b)3,3
18
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
c)6,6
d)12,12
89.Write a program to print the numbers which contains number itself at the end after
performing square of the number between m and n.
for example :
n=76
square = 76*76 = 5776
92.Write a program to print the Arm Strong numbers which is having odd digit in it
between m and n in descending order.
93. 1
212
32123
4321234
32123
212
1
94.#include<studio.h>
19
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
int main()
{
void *vp;
char ch=74, *cp="JACK";
int j=65;
vp=&ch;
printf("%c", *(char*)vp);
vp=&j;
printf("%c",*(int*)vp);
vp=cp;
println("%s",(char*)vp+2);
return 0;
}
a)JCK
b)J65K
c)JAK
d)JACK
95.Write a program to print the numbers which contains number itself at the end after
performing square of the number between m and n.
for example :
n=76
square = 76*76 = 5776
20
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
96.Write a program to perform summation of prime digits of the numbers from m and
n and find second largest digit to the power of second smallest digit of summation
value.
for example:
primeDigitsSum=1234
secondLargestDigit=3
secondSmallestDigit=2
secondLargestToThePowerOfsecondSmallestDigit=2^3=8.
98.Write a program to print the Arm Strong numbers which is having odd digit in it
between m and n in descending order.
99. 1
212
21
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
32123
4321234
32123
212
1
100.Write a program to find the divisor of 9 for given number.
104.Write a program to perform summation of prime digits of the numbers from m and
n and find second largest digit to the power of second smallest digit of summation
value.
for example:
primeDigitsSum=1234
secondLargestDigit=3
secondSmallestDigit=2
secondLargestToThePowerOfsecondSmallestDigit=2^3=8.
22
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
106.Write a program to print the Arm Strong numbers which is having odd digit in it
between m and n in descending order.
for example :m=1
n=10
output: 9 7 5 3 1
107. 1
212
32123
4321234
32123
212
1
108.While loop syntax.
23
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
110.Armstrong number.
class Main {
public static void main(String[] args)
{
int x = 20;
System.out.println(x+" ");
}
static
{
int x = 10;
24
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
System.out.print(x+" ");
}
Options
A.10 10
B.20 20
C.10-20
D.20 10
E.Compile-time Error
116. WAP to print the numbers whose sum of it's digits powered with their respective
position
is equal to the original number between m and n.
for example:
n=135
sumOfDigitsPoweredWithTheirPosition = 1^1 + 3^2 + 5^3 = 135.
(n==sumOfDigitsPoweredWithTheirPosition)
117.WAPTP the numbers which has an even number of digits and the number can be
divided exactly into two parts from the middle.
After equally dividing the number, sum up the numbers and find the square of the
sum.
If we get the number itself as square then print that numbers between m and n.
for example:
n=2025
divideNumberInTwoParts=20|25
sum=20+25
25
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
squareOfSum=(45)^2=(45*45)=2025.
118.Write a program to print the prime numbers, if the reversing order of the prime
number gives you another prime number between m and n.
for example:
n=97(97 is a prime number)
reverse=79(79 is reverse of 97 and 79 is also prime number).
119.WAP to chech summation of second largest digit and second smallest digit of a
number is Neon number or not.
Neon number: Summation of the digits of square of the given is equal to the original
number.
For example:
n=9
square= n*n = 9*9 = 81.
sumOfDigitsOfSquare= 8+1=9
(n==sumOfDigitsOfSquare)
120.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
26
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
121.What is the output of the following Java Program?
#include <stdio.h>
void f()
{
static int i=3;
printf("%d", i);
if(--i) f();
}
main()
{
f();
}
Options
A.3 2 1
B.3 2
C.3
D.3 2 1 0
E.Compile-Time error
#include <stdio.h>
27
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
int main()
{
int m = 20, n = 4;
(m % n == 0) ? printf("Good") : printf("Bad");
return 0;
}
Options
A.Bad
B.Compile-time Error
C.0
D.Run-time Error
123.#include <stdio.h>
int main()
{
int count=0;
for( ; ; ){
if(count == 10)
break;
printf("%d ",++count);
}
return 0;
}
Options:
28
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3.......infinite times
1 2 3 4 5 6 7 8 9 10
123456789
compile-time error
124.#include<stdio.h>
int main()
{
int i=0;
switch(i)
{
case '0':printf("Qualit");
break;
case '1':printf("QualiTlabs);
}
return 0;
}
A)Qualit
B)labs
C)QualiTlabs
D)Compile-time Error
29
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
*
**
***
30
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
137.Pallindrome numbers
138.Fibonacci numbers
139.Prime numbers
140.Armstrong numbers
142.In java the data types byte,short,char values are automatically promoted to
31
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
a)bit
b)int
c)byte
d)short
32
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
alternate prime numbers = 19 11 5 2.
148. A
BAB
CBABC
DCBABCD
149.class A
{
public static void main (String[] args)
{
double a=295.04;
int b=300;
byte c=(byte)a;
byte d=(byte)b;
System.out.println(c+" "+d);
}
}
33
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
a)295 300
b)38 43
c)39 44
d)295.04 300
34