0

I have some problems understanding what are the types after each

 System.out.println(); 

line in this Java code. Right now I am getting errors at line 4 and the rest of the code does not run, can determine what is the problem? Can somebody explain to me what of what type is the result and why? I guess you don't even have to run the code, it just asks for some basic Java knowledge, that I do not have :( From what I understand

         System.out.println ((1<<1) << 2);

delivers 8... but then again, why?

    public static void main(String[] args) {
    String[] s= {"a", "2.0", "3", "eip"};
    System.out.println (s[7/3]);
    System.out.println (Integer.parseInt(s[1])*3.0f);
    System.out.println ((1<<1) << 2);
    System.out.println (s[s.length-1].equals("EIP"));
    System.out.println (Double.parseDouble(s[2]+1) == Integer.parseInt(s[1]));
    System.out.println (1==0|| ! (false & !true));
    }}  
Yoana
  • 75
  • 2
  • 12

2 Answers2

0

s[1] == > 2.0

2.0 is decimal/double hence can not be converted into int using Integer.parseInt(s[1]).

You need Double.parseDouble(s[1]).

(1<<1) << 2 using shifting operator. Study here about this Bitwise and Bit Shift Operators

AJ.
  • 4,526
  • 5
  • 29
  • 41
0

For

System.out.println ((1<<1) << 2);

Try this link for left shift explanation.

Instead of this:

System.out.println (s[s.length-1].equals("EIP"));

try:

System.out.println (s[s.length-1].equalsIgnoreCase("EIP"));
Community
  • 1
  • 1
Aditya Peshave
  • 667
  • 9
  • 26