Computer Science, asked by pouhfdrikm, 7 hours ago

1. ‘System.out.print(“\nOne\tTwo\tThree\nFour\tFive\tSix”);’ Explain the above statement in detail and what output it will produce.

2. Write down the statement to check whether the number is even number or
not. ( Using ternary statement )

3. State the difference between next() and nextLine().

4. Evaluate and predict the output: System.out.println(4+4/10*2-7%3);

Please help me​

Answers

Answered by rathod9999
2

Answer:

1. print command System .out .println("Hello world"); prints the text "Hello ... Accordingly, the above program would produce the print output "Hello World

Explanation:

2.Example 2: Check whether a number is even or odd using ternary operator

import java .util. Scanner;

public class Even Odd {

public static void main(String[] ar gs) {

Scanner reader = new Scanner(System.i n);

System.o ut.print("Enter a number: ");

int num = reader.ne xtInt();

String even Odd = (num % 2 == 0) ? "even" : "odd";

System. out.println(num + " is " + even Odd);

3.Difference between next() and next Line()

next() can read the input only till the space. It can't read two words separated by space. Also, next() places the cursor in the same line after reading the input. next Line() reads input including space between the words (that is, it reads till the end of line n. 4. Predict the output of following Java Program

class Test {

public static void main(String args[]) {

int x = -4;

System.out.println(x>>1);

int y = 4;

System.out.println(y>>1);

}

}

A

Compiler Error: Operator >> cannot be applied to negative numbers

B

-2

2

C

2

2

D

0

2

Java Operators

Discuss it

Question 2

Predict the output of following Java program. Assume that int is stored using 32 bits.

class Test {

public static void main(String args[]) {

int x = -1;

System.o ut.println(x>>>29);

System.out.println(x>>>30);

System.out.println(x>>>31);

}

}

A

7

3

1

B

15

7

3

C

0

0

0

D

1

1

1

Java Operators

Discuss it

Similar questions