Author Topic: Java quiz series  (Read 23557 times)

0 Members and 2 Guests are viewing this topic.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java quiz series
« Reply #90 on: February 23, 2014, 08:10:59 pm »
So what's the next question ? Or has the previous question been accepted as complete.

You can post a new one if you like. ;)

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Java quiz series
« Reply #91 on: February 23, 2014, 08:33:37 pm »
@Deque Sure I would love too  :-*
 

I don't know if this question has been posted earlier or not but if it is not then here you go.


Its a common and very easy question :


Code: [Select]

public class MonkeyDLuffy {
  public static void main(String... string) {
    System.out.println("Kaizoku-oni, orewa naru!");
         //Character c = new Character('\u000d');
   }
}


Does the above code compiles ? Give proper reasons.


"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins

Offline red.evil

  • /dev/null
  • *
  • Posts: 16
  • Cookies: 1
    • View Profile
Re: Java quiz series
« Reply #92 on: March 16, 2014, 12:31:09 am »
It can't compile, because at the beginning of the compiling/parsing progress every unicode sign will be read and replaced. In this case, \u000d, it will be replaced with a newline. This leads to a source code like:
Code: [Select]
public class MonkeyDLuffy {
  public static void main(String... string) {
    System.out.println("Kaizoku-oni, orewa naru!");
         //Character c = new Character('
');
   }
}
and some of the comment is now in a new line and not a comment anymore.

If my answer is correct someone else can ask the next question.
« Last Edit: March 16, 2014, 12:36:27 am by red.evil »

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Java quiz series
« Reply #93 on: March 16, 2014, 04:51:08 pm »
It can't compile, because at the beginning of the compiling/parsing progress every unicode sign will be read and replaced. In this case, \u000d, it will be replaced with a newline. This leads to a source code like:
Code: [Select]
public class MonkeyDLuffy {
  public static void main(String... string) {
    System.out.println("Kaizoku-oni, orewa naru!");
         //Character c = new Character('
');
   }
}
and some of the comment is now in a new line and not a comment anymore.

If my answer is correct someone else can ask the next question.

Correct!

Make the next quiz.
"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins

Offline sherlock

  • /dev/null
  • *
  • Posts: 7
  • Cookies: 2
    • View Profile
Re: Java quiz series
« Reply #94 on: April 04, 2014, 06:33:26 pm »
Hey guys,
I  enjoy this kind of challenges and really would like to see them continue, so i thought it would be a nice way to introduce myself by posting one (since the last one was posted some time ago).
The challenge is probably too easy, simply explain what is happening ;)

Code: [Select]
import java.lang.reflect.Method;

public class Main {

    private String key = "hello";
   
    public Main(){
        key = decrypt(key);
    }

    public static void main(String[] args) {
        final Main m = new Main();
        m.doStuff();
    }
   
    private String decrypt(final String s){
        final char[] c = s.toCharArray();
        for(int i = 0; i < c.length; i++){
            c[i] = (char)(c[i] - 4 - i);
        }
        return String.valueOf(c);
    }
   
    private void hello(){
        System.out.println("Hey guys!");
    }
   
    public void doStuff(){
        try {
            Method m = this.getClass().getDeclaredMethod(key);
            m.invoke(this);
        } catch (Exception e) {
            //I don't care ;)
        }
    }
   
    {{
      key = "ljrsw"; 
    }}

}