public class GreatQues {
public static void main(String[] args) {
int a = 10;
int b =20;
System.out.println("Sum of the numbers : " + a + b);
//System.out.println("Diff of the numbers : " + a - b); // (Line 1) Compile time error
System.out.println("Product of the numbers : " + a * b);
System.out.println("Division of the numbers : " + a / b);
short x = 127;
short y = 140;
//short z = x + y; // Compile time error (Line 2)
System.out.println(127 + 140);
}
}
Output :
Sum of the numbers : 1020
Product of the numbers : 200
Division of the numbers : 0
267
Explanation :
When we write sysout ( String + some integer), the compiler treats that interger as a String only and just appends the value to the String.
- operator is not overloaded in String, therefore, the Line 1 gives compile time error saying : - operator is undefined for arguments of type String and int.
Line 2 gives compile time error because any mathematical operation on two shorts / ints / bytes always gives int as result.
Welcome Message
Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.
Top Navigation Menu
Showing posts with label Adobe. Show all posts
Showing posts with label Adobe. Show all posts
January 9, 2010
December 27, 2009
Program to swap first two nodes of a list -> Adobe Question
public void interchangeFirstTwo(){
Node temp = head;
Node next = temp.next;
temp.next = next.next;
next.next = temp;
head = next;
}
Node temp = head;
Node next = temp.next;
temp.next = next.next;
next.next = temp;
head = next;
}
Labels:
Adobe,
Code,
DataStructure,
java,
Swap First two nodes
Program to swap first and last node of a list -> Adobe Question
public void swapFirstLast(){
Node current = head;
Node previous = null;
while(current.next != null){
previous = current;
current = current.next;
}
Node temp = head;
current.next = temp.next;
previous.next = temp;
temp.next = null;
head = current;
}
Node current = head;
Node previous = null;
while(current.next != null){
previous = current;
current = current.next;
}
Node temp = head;
current.next = temp.next;
previous.next = temp;
temp.next = null;
head = current;
}
Labels:
Adobe,
Code,
DataStructure,
java,
Linked List,
Swap First and Last
Subscribe to:
Posts (Atom)