# Solutions to the Try It Out Exercises in Beginning Programming with Java For Dummies, 6th Edition by Barry Burd

## In this chapter:

### Narcissist's code

```import java.util.Scanner;

public class Narcissist {

public static void main(String[] args) {
var keyboard = new Scanner(System.in);
String name;
int howMany;

name = keyboard.nextLine();
System.out.print("How many times would you like me to display your name? ");
howMany = keyboard.nextInt();

for (int i = 1; i <= howMany; i++) {
System.out.println(name);
}

keyboard.close();
}
}
```

### British pounds to US dollars

```public class PoundsToDollars {

public static void main(String[] args) {

System.out.println("Pounds   Dollars");

for (int pounds = 1; pounds <= 9; pounds++) {
System.out.print("  ");
System.out.print(pounds);
System.out.print("        ");
System.out.println(pounds * 1.25);
}

}
}
```

### Do I hear an echo?

```import java.util.Scanner;

public class Echo {

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int number;

do {
System.out.print("Enter a number: ");
number = keyboard.nextInt();
System.out.println(number);
System.out.print("Continue? (y/n) ");
System.out.println();

System.out.println("Done!");

keyboard.close();
}

}
```

### Tally ho!

```import java.util.Scanner;

public class Tally {

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int number, sum = 0;

do {
System.out.print("Enter a non-zero number, or zero to quit: ");
number = keyboard.nextInt();
sum += number;
} while (number != 0);

System.out.println(sum);

keyboard.close();
}

}
```