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:
Instructions
Input
Multiple lines containing an integer on each.
2
3
4
-1
-5
1
0Output
A line containing an integer.
10int 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” );
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·yOutput
A line containing a string.
Correctby 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:
Input
The first line contains an odd positive integer.
The next lines contains an integer.
5
1
3
4
5
2Output
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