Loading

Guide me how to read below code to produce output.

3 posts / 0 new
Last post
Offline
Joined: 11/13/2009
Guide me how to read below code to produce output.

Hi,

I don't know how to read the below code to produce the outputs.

QUESTION:State the expected output from the below codes. [5]
for(int x=5; x <=100; x++)
{
if(x % 10) ==0)
break;
System.out.println(x);
}

QUESTION: Trace the following code, and produce its outputs. [5]
String data = ‘’data base’’;
int x = data.length();
int y = data.indexOf(‘a’);
int z = data.lastIndexOf(‘g’);
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(10%x);
System.out.println(data.equals(‘’database’’));

Offline
Joined: 10/30/2010
QUESTION:State the expected

QUESTION:State the expected output from the below codes. [5]
for(int x=5; x {
if(x % 10) ==0)
break;
System.out.println(x);
}

ANSWER :
its a program that terminate when your if statement is test(if its true it then terminate ) i.e if the result is equal to zero it then terminate.
for the program above your first input value is x=5 and (5%10==0) is not equal to zero so your first output is 5.
your next x=6 because X=X+1 base on your increment (6%10==0) is not equal to zero so your next output is 6
continuously you keep incrementing x by 1 i.e X= X+1
up to x=10 and (10%10==0) is true so the program then terminate ....
therefore your outputs = [5,6,7,8,9]

Offline
Joined: 10/30/2010
QUESTION: Trace the following

QUESTION: Trace the following code, and produce its outputs. [5]
String data = ‘’data base’’;
int x = data.length();
int y = data.indexOf(‘a’);
int z = data.lastIndexOf(‘g’);
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(10%x);
System.out.println(data.equals(‘’database’’));

ANSWER :
x will be 9
y will be 1
z will be -1
10%x will be 1
data.equals(‘’database’’) will be false

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.