Java | JSP | JSF Answers

Questions answered by Experts: 3 611

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

4. Gathering Positivity

by CodeChum Admin

I always want to look at the positive side of things, so I decide to seriously look at positive numbers, too!


Will you code along with me?


Instructions:

  1. Using the do…while() loop, continuously scan for integers, but add up only all the positive integers and store the total in one variable.
  2. The loop shall only be terminated when the inputted integer is zero. Afterwards, print out the total of all inputted positive integers.

Instructions

  1. Using the do…while() loop, continuously scan for random integers, but add up only all the positive integers and store the total in one variable.
  2. The loop shall only be terminated when the inputted integer is zero. Afterwards, print out the total of all inputted positive integers.

Input

Multiple lines containing an integer on each.

2
3
4
-1
-5
1
0

Output

A line containing an integer.

10




int a = 5, b = 10, c = 16, d = 0;

What are the outputs after the following Java statements are executed?

(a) if ( d )

else

system.out.println( “true” ); system.out.println( “false” );

(b) if ( a != 5 || b = = 10 ) system.out.println( “true” );

else

system.out.println( “false” );

(c) if ( b <=a && c/d)

system.out.println( “true” );

else

(d) if (a > 5 || d) else

system.out.println( “false” );

system.out.println( “true” ); system.out.println( “false” );

(e) if ( a*d >= d++ )

system.out.println( “true” );

else

system.out.println( “false” );

(f) if (d/a < c*b )

system.out.println( “true” );

else

system.out.println( “false” );


4. Is It You, Cody?

by CodeChum Admin

Can you identify if Cody's name is spelled right? If so, then make a program that accepts four one-letter strings separated by space and print "Correct" if the inputted strings, combined in order, spell the name Cody correctly. If not, print "Wrong". It doesn't matter if it's in uppercase or lowercase, as long as it's spelled correctly, it's considered correct.


Now, will you take on this task?


Input

A line containing four one-letter strings separated by a space.

c·O·D·y

Output

A line containing a string.

Correct




8. Groupings

by CodeChum Admin

Did you know that you can also reverse lists and group them according to your liking with proper code? Let's try it to believe it.


Instructions:

  1. Create a variable that accepts a positive odd integer.
  2. Create an empty list. Then, using loops, add random integer values into the list one by one. The number of values to be stored is dependent on the inputted odd integer on the first instruction.
  3. Reverse the order of the list. Then, print out the list's new order in this manner:
  4. [first-half values]-[middle value]-[second-half values], just like that of the sample output. Make use of list slicing that you’ve learned from the past lessons to easily achieve this segment.

Input

The first line contains an odd positive integer.

The next lines contains an integer.

5
1
3
4
5
2

Output

A line containing a list.

[2,5]-[4]-[3,1]

class Tool {

private String name = "B tool"; public Tool(String name)

{

this.name = name; }

}

class Hammer extends Tool {

// Suppose Crackable interface exists public void crack(Crackable b)

{

// implementation to crack object b}

}

Will it compile? YES or NO. Give reason, if No.


package studentBase;

class Test

{

String greet = “Hi”;

String name = “Smedley”;

String nickName = name.substring (0,2); If (nickName == name.substring(0,2))

System.out.println(“has real nickname”);

else if (greet + name == greet + nickName);

System.out.println(“no real nickname”);

Else

System.out.println(“hmmm ... changed names?”); }

Will it compile? YES or NO. Give reason, if No.


Write an if-else statement that outputs the discount

The communication company offers a discount to customer who is taking at least 12-

month plan. The discount arrangement is as below: Business customer:

12/18 months 15% discount

24 months 25% discount

Non-Business customer

12/18 months 10% discount

24 months 15% discount

The variables customerType is of type char, period is of type int and discount is of


What does the following fragment display? (


) class MyClass

{

public static void main(String[] args) {

boolean b = true; int i = 2;

do

{

i++;

b = !b; } while (b);

System.out.println(i); }

}



Consider the following program written in Java and answer the question:

1. import java.util.*;

2. class Arraylist

3. {

4. public static void main(String args[])

5. {

6. ArrayList obj = new ArrayList();

7. obj.add("B");

8. obj.add("C");

9. obj.add("C");

10. obj.add("D");

11. obj.remove(2);

12. System.out.println(obj.get(1));

13. }

14. }

What would be the output of the statement when the program is executed? 


There are different kinds of numbers, but among them all, the most commonly used numbers in our daily lives are those positive ones. So, I only want you to count all the positive numbers from the 4 outputted values and print out the result.





Go and search for the positive ones among these four!



Input



A line containing four numbers (may contain decimal places) separated by a space.



2·-4·3.6·1


Output



A line containing an integer.



3

LATEST TUTORIALS
APPROVED BY CLIENTS