You are on page 1of 3

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) {
System.out.println("*”);
} else {
break;
}
}
}
}

3. Ce se va afisa ?

    String str = null;

    try {

        str.charAt(1);

    } catch (Exception e) {

        System.out.println("there is an exception");

    } catch (NullPointerException e) {

        System.out.println("there is a null pointer exception");

    }
4. Ce se va afisa ?

class Parent
{
int value = 1000;
Parent() {
System.out.println("Parent Constructor");
}

void draw() {
System.out.println("draw parinte val="+value);
}
}

class Child extends Parent {


int value = 10;
Child() {
System.out.println("Child Constructor");
}
void draw() {
System.out.println("draw copil="+value);
}
}

class DerivationInterview {
public static void main(String[] args) {
Child obj=new Child();
System.out.println("Reference of Child Type :" + obj.value);

Parent par = obj;


par.draw();

System.out.println("Reference of Parent Type : " + par.value);

if (par instanceof Child) {


System.out.println("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);
System.out.println(name);

Interview i = new Interview();


Person p = i.new Person("Popescu", 30);
changePerson(p);
System.out.println(p.name);
System.out.println(p.age);
}

private static void changeName(String name, boolean isWoman) {


if (isWoman==true) {
name = "Dra. " + name;
} else {
name = "Dl. " + name;
}
}

private static void changePerson(Person pers) {


pers.name = "Ionescu";
pers.age = 50;
}

public class Person {


String name;
int age;
Person (String name, int age) {
this.name=name;
this.age=age;
}
}
}

7. Reverse string Hello without java library functions

8. How to convert String to Integer? What about Integer to String?

You might also like