QuestionQuestion

1. Which of the following can be used in a Java program as identifiers? Check all of the identifiers that are legal.
1. sum_of_data
2. AnnualSalary
3. _average
4. 42isThesolution
5. B4
6. ABC
7. for
8. println
9. "hello"
10. first-name

A) 1, 2
B)1, 2, 3
C)1, 3, 5, 6
D)1, 2, 3, 5, 6, 8
E)1, 2, 3, 5, 6, 10

2. Of the below, what is an invalid variable name?
A)Shiva_Mani_98480_22338
B)1942_a_love_story
C)Balu_ABCDEFG
D)___s_ss_ssshh
E)None of the above

3. What lines fail to compile? public class MoviesAreFun {

public static void main(String[] args) {
int arya2 = 2; /* LINE A */
double life_is_beautiful = 3.0; /* LINE B */
char 7/gbrundavan_colony = 'G'; /* LINE C */
float LIFE_OF_PI = 3.14; /* LINE D */
short 3idiots = 255; /* LINE E */
}
}

A)ABCE
B)CE
C)CDE
D)ABCDE

4. Identifiers can not starts with?
A)Characters
B)Digits
C)underscore ( _ ) symbols
D)None of the above

5. What will be the output of the following program?
public class ScopeOfVariables {
public static void main(String[] args) {
int x = 10;
System.out.print(x + ", " + y);
int y = 20; x = 15;
System.out.print(" - " + x + ", " + y);
}
}
A)10, 20 - 15, 20
B)10, 0 - 15, 20
C)Compilation Error
D)Runtime Error

6. What will be the output of the following program?
public class Book {
public static void main(String[] args) {
String book = "java";
int pages;
System.out.println("Book name " + book);
double price = 275.50D;
System.out.println("Pages " + pages);
pages = 300;

System.out.println("Price " + price);
}
}

A) Book name java
Pages 300
Price 275.50D
B) Book name java
Pages 300
Price 275.5
C) Book name java
Pages 0
Price 275.5
D) Compilation Error
E) Runtime Error

7- Determine output:
class A{
public static void main(String args[]){ int x; x = 10; if(x == 10){ int y = 20;
System.out.print("x and y: "+ x + " " + y); y = x*2; } y = 100;
System.out.print("x and y: " + x + " " + y);
}
}
A.10 20 10 100
B.10 20 10 20
C.10 20 10 10
D. Compile time Error

8- Determine the output? double STATIC = 2.5;
System.out.print(STATIC);
A.Prints 2.5
B.Rraises an error as STATIC is used as a variable which is a keyword
C.Raises an exception
D.None of these

9 -What is the output? class Test{ static int x =10; public static void main(String[] string){
Test test1 = new Test();
Test test2 = new Test();
test1.x += 1;
System.out.println( test1.x + test2.x);
}
}
A.20
B.21
C.22
D.Compilation Error
E.Throws Exception

10-Whats the output?
class Test{ static boolean isOk;
public static void main(String[] string){
System.out.println(isOk);
}
}
A.Prints true
B.Prints false
C.Will not compile as boolean is not initialized
D.Will not compile as boolean can never be static

11-Write a java program to print given number is even or odd?

12- Write a java program to print below output: -9, -8, -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9

13-Write a java program to print 1 to 10 numbers in descending order. Ex. 10, 9, 8, 7,6,5,4,3,2,1

14-Write a java program to print given number is 2 digit or 3 digit number.

15-Write a java program (method) to accept N number of strings as arguments and concatenate them?

16-Write a java program to accept 2 numbers and do all the arithmetic operations on them?

17-Write a java program swap 2 numbers with using third variable?
Ex. Intput A=10, B=20
Output A=20, B=10

18. Write a program to find greatest among three using if else

19. Write a program to find greatest among three using ternary operator

20. Write a program to find N to power M, where value of N and M can be taken at run time (command line argument/Run configuration)

21. write a program to print below pattern
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

22- write a program to find sum of diagonal elements from above pattern.

23-Write Java program to check if a number is palindrome in Java? ( 121 is palindrome, 321 is not)

24-Write Java program to check if a number is Armstrong number or not? (input 153 output true, 123 output false) An Armstrong number of 3 digit is a number for which sum of cube of its digits are equal to number e.g. 371 is an Armstrong number because 3*3*3 + 7*7*7 + 1*1*1 = 371).

25-Write a Java program to calculate factorial of an integer number ? factorial of n is : n*(n-1)*…1.

26-Write a class with variable name,age ,isMarried and salary. Initialize the variable with constructor and print the value ?

27-How to find sum of all digits of a number in java? like for 123 sum=6

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

1. 1. D)1, 2, 3, 5, 6, 8
2. 2. B)1942_a_love_story
3. 3. C)CDE
4. 4. B)Digits
5. C)Compilation...

By purchasing this solution you'll be able to access the following files:
Solution.docx.

$17.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats