0% found this document useful (0 votes)
11 views2 pages

Java Programming Code Examples

The document contains a Java quiz with various coding problems and examples. It includes loops, conditionals, recursion, and string manipulation tasks. Each section presents a different programming challenge for the reader to solve.

Uploaded by

adrija1704
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)
11 views2 pages

Java Programming Code Examples

The document contains a Java quiz with various coding problems and examples. It includes loops, conditionals, recursion, and string manipulation tasks. Each section presents a different programming challenge for the reader to solve.

Uploaded by

adrija1704
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

JAVA QUIZ

1. int a = 1; [Link] str = "JavaProgramming";


for (int i = 1; i <= 3; i++) String result = "";
{ for (int i = 0; i < [Link](); i++) {
for (int j = 1; j <= i; j++) if (i % 2 == 0) result += [Link](i); else result += "*";
{ }
if ((i + j) % 2 == 0) [Link](result);
a += 2; [Link] str = "racecar";
else a -= 1; String rev = "";
[Link](a + " "); for (int i = [Link]() - 1; i >= 0; i--)
} {
[Link](); rev += [Link](i);
} }
2. int[] arr = {2, 5, 8, 11, 14}; [Link]([Link](rev));
int sum = 0; [Link] x = 5;
for (int i = 0; i < [Link]; i++) { for (int i = 1; i <= x; i++)
if (arr[i] % 2 == 0) {
{ for (int j = 1; j <= i; j++)
if (arr[i] % 3 == 0) {
sum += arr[i]; [Link]((i + j) + " ");
else sum -= arr[i]; }
} [Link]();
else sum += 1; }
} 7.
[Link](sum); String str = "java";
for (int i = 0; i < [Link](); i++)
3. public class RecursionExample {
{ [Link]((char)([Link](i) + 1));
public static void main(String[] args) { }
[Link](sum(5)); [Link] class Fibonacci {
} public static void main(String[] args) {
[Link](fib(5));
public static int sum(int n)
}
{
public static int fib(int n) {
if (n <= 1)
if (n <= 1)
return n;
return n;
return n + sum(n - 2);
return fib(n - 1) + fib(n - 2);
}
}
}
}
[Link] count = 0; 15. int num = 4, product = 1;

for (int i = 1; i <= 3; i++) { for (int i = 1; i <= num; i++)

for (int j = i; j <= 3; j++) { {


for (int j = i; j <= num; j++)
count += i + j;
{
}}
product *= j % i == 0 ? i : j;
[Link](count);
}}
[Link] str = "ICSEExam";
[Link](product);
String result = ""; [Link] a = 12, b = 3, result = 0;
for (int i = 0; i < [Link](); i++) { for (int i = 2; i <= 5; i++) {
if (i % 3 == 0) a -= b++ * i;
result += [Link]([Link](i)); result += a % b;

else b += i;
}
result += [Link](i);
[Link](result);
}
[Link] sum = 0;
[Link](result);
for (int i = 1; i <= 5; i++)
[Link] a = 3;
{
for (int i = 0; i < 4; i++) {
int temp = i;
a = (a % 2 == 0) ? a * 2 : a + 3; while (temp > 0) {
} sum += temp % 2 == 0 ? temp : -temp;
[Link](a); temp--;
[Link] a = 0; }}

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= i; j++) { [Link](sum);


[Link] num = 4, total = 0;
a += i * j;
for (int i = 1; i <= num; i++) {
}
for (int j = 1; j <= i; j++) {
}
total += (i * j) % 2 == 0 ? j : i;
[Link](a);
}
13. }
int x = 1; [Link](total);
for (int i = 0; i < 4; i++) [Link] a = 6, b = 3;
{ for (int i = 2; i <= 5; i++) {

x += i % 2 == 0 ? i : -i; a = (a * b) % i;

} if (a % 2 == 0) {
b += 2;
[Link](x);
}
[Link] a = 10, b = 20;
else {
boolean result = a++ < b-- && ++a > --b;
[Link](result); b -= 1;
}}
[Link](a + " " + b);
[Link](a + " " + b);

You might also like