0% found this document useful (0 votes)
98 views2 pages

Coding Challenge 1 HelloWorld

The document provides 3 coding exercises to print different outputs using Java print statements. The first exercise prints a shopping list with indents. The second rewrites the first with a single print statement. The third prints a phrase with words on separate lines. Sample solutions for each exercise using println and print statements are also provided.

Uploaded by

nkshahane23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views2 pages

Coding Challenge 1 HelloWorld

The document provides 3 coding exercises to print different outputs using Java print statements. The first exercise prints a shopping list with indents. The second rewrites the first with a single print statement. The third prints a phrase with words on separate lines. Sample solutions for each exercise using println and print statements are also provided.

Uploaded by

nkshahane23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Coding Challenge 1

HelloWorld

Exercise 1
Create a program which produces the following output:

SHOPPING LIST 
- Milk 
> Semi-skimmed 
> Medium 
- Eggs 
> Free-range 
- Bread 

Exercise 2
If you used multiple print/println statements in Exercise 1, rewrite the program using only a
single print/println method (or vice versa).

Exercise 3
Create a program which produces the following output:

The 
Cake 
Is A 
Lie. 

As a rule, each word must go in its own print/println method.

Possible Solutions

Exercise 1
System.out.println("SHOPPING LIST");
System.out.println("\t- Milk");
System.out.println("\t\t> Semi-skimmed");
System.out.println("\t\t> Medium");
System.out.println("\t- Eggs");
System.out.println("\t\t> Free-range");
System.out.println("\t- Bread");
Exercise 2
System.out.print("SHOPPING LIST\n\t- Milk\n\t\t> Semi-skimmed\n\t\t>
Medium\n\t- Eggs\n\t\t> Free-range\n\t- Bread");

Exercise 3
System.out.println("\n\nThe");
System.out.println("\tCake");
System.out.print("Is");
System.out.println("\t\tA");
System.out.print("\tLie.");

You might also like