0% found this document useful (0 votes)
891 views

Java Basic Programs (Java Programming)

This document contains questions about basic Java programming concepts and programs. It includes questions about data types, variables, operators, functions, strings, arrays, loops, patterns, recursion, classes and more. Sample programs are provided to demonstrate concepts like calculating sums, factorials, Fibonacci series, palindrome checks and other numerical operations.

Uploaded by

mahi jonssy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
891 views

Java Basic Programs (Java Programming)

This document contains questions about basic Java programming concepts and programs. It includes questions about data types, variables, operators, functions, strings, arrays, loops, patterns, recursion, classes and more. Sample programs are provided to demonstrate concepts like calculating sums, factorials, Fibonacci series, palindrome checks and other numerical operations.

Uploaded by

mahi jonssy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

JAVA BASIC PROGRAMS (JAVA PROGRAMMING)

1.Basic java programs?

2.Difference between c,c++,java?

3.Explain about java?

4.What you mean by ASCII?

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?

7.Which of the following is not a number data type?


a)int
b)double
c)char
d)byte

8.Write a program that will take 5 numbers as input in java?

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)

a)Line 1 will not compile


b)Line 2 will not compile
c)Line 3 will not compile
d)Line 4 will not compile
21.Types of operators

22.Features of java

23.Jvm means?

24.Java is a independent language or dependent language ?

25. Write a program for swapping 2 numbers and write palindrome program for the
swapping numbers

26.Write a program to print below patterns?


13579
1357
135
13
1

6
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)

27.Write a program to print first 10 fibonacci series.

28.Write a program to print first 10 fibonacci series in reverse order.

29.write a program given number is boolean ouput with number is


divisible by 3&5&7&10

30.write a program to print number is even or odd.

31.Write a program to print 1-10 numbers

30.Write a program to print numbers in matrix type.


ex:[123
456
789]

31.Pallindrome program.

32.Write a program to convert string into int.

33.Print pascal triangle.


1
1 2 1

7
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

34.Write a program to print fibonacci numbers upto 20?

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).

52)Write a program to perform summation of second smallest digit of numbers


between x and y.
and check whether the summation is Arm strong number or not.

53)Write a program to check 10th strong number's second largest digit is prime or not.

54)Write a program for the below scenario,


A person starts mango business with zero investment, and with the help of his friend
he buys single mango,

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?

57.What is the difference between JDK,JRE,JVM.

58.Given two ranges (L1,R1) and (L2,R2) maximum product

59.print the sum of all the prime factors of n

60.Find the sum of the series of 'n' number of Integers.


61.Write a program to perform summation of first digit and last digit of a number is
Strong number or not.
62.Write a program to check whether the given number is ArmStrong or not,

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.

65.Factorial of a given number using recursion.


patterns:
i/p: n=5;
o/p: 5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
and also
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1

66.x to the power of y in recursion

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.

77.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.

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.

82.Write a program on Prime numbers from 1-100.


83.Write a program to print spy fibonacci numbers between m and n.
84.Write a program to print the numbers which is having prime digit in it between m
and n.
85.Write a program to perfom summation of odd digit of numbers between m and n,
and print factorial of second smallest digit of summation value.
86.Write a program to print the palindrome numbers whose digits product is less than
99.
87. 1
11
121
133 1
146 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
88.Pallindrome number.
#include<stdio.h>
int sumdig(int);

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

90.Write a program to perform summation of prime digits of the numbers between m


and n and find second largest digit to the power of second smallest digit of summation
value.

91.Write a program to print perfect numbers between m and n whose summation of


digits is less than 15.

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.

97.Write a program to print perfect numbers between m and n whose summation of


digits is less than 15.
for example :
pefectNumber=28
sumOfDigit=10
(sumOfDigit<15)

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.

101.Write a program to find even and odd for given n number.

102.For loop syntax.


103.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

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)

105.Write a program to print perfect numbers between m and n whose summation of


digits is less than 15.
for example :
pefectNumber=28
sumOfDigit=10
(sumOfDigit<15)

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)

109.If statement syntax.

110.Armstrong number.

111.Write a program for Armstrong numbers?

112.Find a number is prime number or not

113.Print length of linkedlist.

114.Fibonacci series give the 5 numbers

115.What is the output of the following Java Program?

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

122.What is the output of the following C Program?

#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

125.Print the pattern.

29
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
*
**
***

126.Write a program to print sum of all the numbers

127.Write a program to print nth factorial.

128.Write a program to print

129.write a program to print the number in reversing order blw m and n.

130.Multiply Two Numbers without using (Multiplication Operator)in c#


Enter first number:9
Enter second number:6
multiplication of 9 and 6 is 54

131.Write a program to Reverse Number using Recursion


Enter a number :234
Reversed Number:432

132.prime numbers between m and n range.

133.Pallindrome recursion program.

30
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)

134.1.Prime number or not?

135.Have a mathechallenge(num) add up all the numbers from 1 to num.For example:If


the input is 4 then your program should return 10 because 1+2+3+4=10.
For the test cases,the parameter num will be any number from 1 to 1000.
1.Pattern programs.

136.Check given element is prime or not.

137.Pallindrome numbers

138.Fibonacci numbers

139.Prime numbers

140.Armstrong numbers

141.In the following syntax what is the value of B?


byre b=50;
b=b*2
a)100 b)Error c)2 d)50

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

143.What will be the output of the following code?


byte x=64,y;
y=(byte)(x<<2);
System.out.println(y);
a)1
b)0
c)64
d)2
144.Write a program to print summation of the digits of palindrome numbers until the
summation of the digits consists only single digit,
and print the summation if and only if it is a prime number along with the number
between 100 to 1000.
for example: n=353
sumOfDigits1=3+5+3=11
sumOfDigits2=1+1=2( 353= 2 is prime number).

145.Write a program to print alternate prime numbers between m and n in descending


order.
for exmaple: m=1
n=15

32
JAVA BASIC PROGRAMS (JAVA PROGRAMMING)
alternate prime numbers = 19 11 5 2.

146.Write a program to perform summation of perfect square numbers between m and


n,
and find smallest digit to the power of largest digit of summation value.
for ex: sumOfPefectSquare= 25
squareRootOfSum= 5.
147.Write a program to print the factorial of second smallest digit of ArmStrong
numbers between m and n along with the number.

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

You might also like