1. Sa se scrie un mic program java care sa afiseze un bradut format din “*”.
Functia: printBradut(int lines)
Ex apel printBradut(3) :
*
***
*****
2. Cate “*” se vor afisa?
public class Test {
public static void main(String args[]) {
int x = 0;
int y = 0;
while (true) {
if (++x <= 10 || ++y <= 10) {
[Link]("*”);
} else {
break;
}
}
}
}
3. Ce se va afisa ?
String str = null;
try {
[Link](1);
} catch (Exception e) {
[Link]("there is an exception");
} catch (NullPointerException e) {
[Link]("there is a null pointer exception");
}
4. Ce se va afisa ?
class Parent
{
int value = 1000;
Parent() {
[Link]("Parent Constructor");
}
void draw() {
[Link]("draw parinte val="+value);
}
}
class Child extends Parent {
int value = 10;
Child() {
[Link]("Child Constructor");
}
void draw() {
[Link]("draw copil="+value);
}
}
class DerivationInterview {
public static void main(String[] args) {
Child obj=new Child();
[Link]("Reference of Child Type :" + [Link]);
Parent par = obj;
[Link]();
[Link]("Reference of Parent Type : " + [Link]);
if (par instanceof Child) {
[Link]("Value accessed through parent reference with typecasting is " +
((Child)par).value);
}
}
}
5. Switch the values without creating a new variable.
int a = 3;
int b = 5;
6. Ce se va afisa ?
public class Interview {
public static void main(String args[]) throws Exception {
String name = "Mary";
boolean isWoman = true;
changeName(name, isWoman);
[Link](name);
Interview i = new Interview();
Person p = [Link] Person("Popescu", 30);
changePerson(p);
[Link]([Link]);
[Link]([Link]);
}
private static void changeName(String name, boolean isWoman) {
if (isWoman==true) {
name = "Dra. " + name;
} else {
name = "Dl. " + name;
}
}
private static void changePerson(Person pers) {
[Link] = "Ionescu";
[Link] = 50;
}
public class Person {
String name;
int age;
Person (String name, int age) {
[Link]=name;
[Link]=age;
}
}
}
7. Reverse string Hello without java library functions
8. How to convert String to Integer? What about Integer to String?