0% found this document useful (0 votes)
7 views3 pages

Java Questons

The document contains a series of programming tasks and questions primarily focused on Java programming concepts, including conditional statements, loops, and basic arithmetic operations. It includes specific tasks such as determining if a number is even or odd, sorting numbers, calculating bank interest, and identifying prime numbers. Additionally, it poses multiple-choice questions regarding the output of various Java code snippets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java Questons

The document contains a series of programming tasks and questions primarily focused on Java programming concepts, including conditional statements, loops, and basic arithmetic operations. It includes specific tasks such as determining if a number is even or odd, sorting numbers, calculating bank interest, and identifying prime numbers. Additionally, it poses multiple-choice questions regarding the output of various Java code snippets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Write a program to determine the keyboard input number is even or odd using the if else
statement.

2. Write the program to display the positive, negative or zero from given number using
keyboard.

3. Write a program to display descending sorted order by input three number accepted from
the keyboard.

4. Write a program that uses a SWITCH statement that print Male if a variable gender is
‘m’, print Female if gender is ‘f’ and prints Wrong Character response otherwise.

char gender=’M’;

5. Write a program that uses a if else statement to set ticket to 1 if speed is greater than 55
and to 0 otherwise.

6. Suppose you deposit $100 per month in bank account every month for a year . Every
month, after the deposit has been made, interest at the rate of 2% is added to the balance.
Write a program to calculate the balance for one year.

7. Write a program to find and output the prime number, the accept number from the
keyboard.

8. Write a java program to determine vowel or not following given character. Using switch
statement.
char ch=’a’; // ch = a or e or i A E I O U
9. Write a java program to calculate the sum and output between 1to 100.
(Using for loop)
10. Review a java program following program if user input number is 159 .
import java.util.Scanner;
class VariableSum {
public static void main(String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print("Input an integer between 0 and 1000: ");
int num = input.nextInt();

int firstDigit = num % 10;


int remainingNumber = num / 10;
int SecondDigit = remainingNumber % 10;
remainingNumber = remainingNumber / 10;
int thirdDigit = remainingNumber % 10;
remainingNumber = remainingNumber / 10;
int fourthDigit = remainingNumber % 10;
int sum = thirdDigit + SecondDigit + firstDigit + fourthDigit;
System.out.println("The sum of all digits in " + num + " is " + sum);

}
}

===============================================================================

1)What will be printed as the output of the following program?


public class testincr{
public static void main(String args[])
{
int i = 0;
i = i++ + i;
System.out.println(“I = ” +i);
}
}
(a) i = 0 (b) i = 1 (c) i = 2 (d) i = 3 (e) Compile-time Error.

2) What is the output of the following program:


public class teststatic
{ static int i = 1;
public static void main(String args[])
{ System.out.print(i+” , “);
m(i);
System.out.println(i);
}
public static void m(int i)
{ i += 2; }
}
(a) 1 , 3 (b) 3 , 1 (c) 1 , 1 (d) 1 , 0 (e) none of the above.

3) Consider the following Java program :


public class Compute
{ public static void main (string args [ ])
{ int result, x ;
x=1;
result = 0;
while (x < = 10)
{ if (x%2 == 0)
result + = x ;
++x;
}
System.out.println(result) ;
}
}
Which of the following will be the output of the above program?
(a) 55 (b) 30 (c) 25 (d) 35 (e) 45

4) What will be the output of the following))g Java code?


class increment {
public static void main(String args[])
{ int g = 3;
System.out.print(++g * 8); }
}
a) 32 b) 33 c) 24 d) 25 e)31

5) What will be the output the following Java Coding?.


Int i.
For(i=1;i<=10;i++)
{
If(i>=6)
{
Break;
}
System.out.print(I +”\t”);
}
a)6 7 8 9 10 b) 1 2 3 4 5 c) 1 2 3 4 5 6 7 d) 5 6 7 8 9 10

You might also like