arten_1337

Untitled

Jul 13th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. class codingQuestion3 {
  2.  
  3. public static void concat1(String s1) {
s1 = s1 + "test1";
}
  4.  
  5. public static void concat2(StringBuilder s2) {
s2.append("test2");
}
  6.  
  7. public static void concat3(StringBuffer s3) {
s3.append("test3");
}
  8.  
  9. public static void main(String[] args) {
  10.  
  11. String s1 = "test1";
concat1(s1); test1test1
System.out.println("String: " + s1);
StringBuilder s2 = new StringBuilder("test2");
concat2(s2); test2test2
System.out.println("StringBuilder: " + s2);
StringBuffer s3 = new StringBuffer("test3");
concat3(s3);
System.out.println("StringBuffer: " + s3);
}
}
  12.  
  13.  
  14. abstract class Bank {
abstract int getRateOfInterest();
}
  15.  
  16. class SBI extends Bank {
int getRateOfInterest() {
return 7;
}
  17.  
  18. void test() {
System.out.println("test called");
}
}
  19.  
  20. class PNB extends Bank {
int getRateOfInterest() {
return 8;
}
}
  21.  
  22. class TestBank {
public static void main(String args[]) {
Bank b = new SBI();
b.test(); 
SBI k = new SBI();
k.test(); test called
int interest = b.getRateOfInterest();
System.out.println("Rate of Interest is: " + interest + " %");
}
}
  23.  
  24.  
  25.  
  26.  
  27. class P {
static void ab() {
System.out.println("P");
}
}
  28.  
  29. class A extends P {
static void ab() {
System.out.println("a");
}
}
  30.  
  31. class B extends P {
static void ab() {
System.out.println("b");
}
  32.  
  33. public static void main(String ar[]) {
P p = new A();
A a = new A();
p.ab();
p = new B();
p.ab();
a.ab();
}
  34.  
  35.  
  36.  
  37.  
  38. 10
  39.  
  40. 6 4
  41. 3 3 2 2
  42.  
  43.  
  44.  
  45.  
  46. Public boolean isSumTree(TreeNode root)
  47. {
  48. return helper(root);
  49.  
  50. }
  51.  
  52. Public boolean helper(TreeNode root)
  53. {
  54. if(root == null)
  55. return true;
  56. if(root.left == null && root.right == null)
  57. return true;
  58. int sum = root.left == null?0:root.left.data + root.right == null?0:root.data;
  59. if(sum != root.data)
  60. return false;
  61.  
  62. return helper(root.left) && helper(root.right);
  63.  
  64. }
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment