Skip to content

keadat1st/20_Input_og_loops

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

20_Input_og_loops

Opsamling på øvelser i sidste modul

  • udregn gennemsnittet af tilfældige tal i WhileLoops.java
  • udregn hypotenusen ud fra katederne vha. pytagoras i WhileLoops.java

Scanner objektet

  • udvid de to opgaver med brug af scanner objektet, så der kan indtastes
  • lav et program, der udregner sum og gennemsnit af positive heltal. Når der tastes 0, skal der beregnes (uden at inkludere 0). Brug en while løkke.
  • udvid skole-projektet, så I kan indlæse oplysninger for en student og udskrive den igen

Øvelser med for-løkker

1 . Print the folowing to the console using a for loop.

    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *
    * * * * * * * * * *

2 . Using a for loop, print this to your console:

    1, 2, 3, 4, 5, 6, 7, 8, 9, 10

3 . Create a method called greet(), that takes an int as a parameter. The method should print out hello there the amount of times specified in the methods parameter.

    // Example:
    greet(3);
    // Should print
    Hello
    Hello
    Hello

4 . Create a method called print(), that takes an int as a parameter. The method should print out the same as in exercise 1, but should be able to print out a dynamic amount of stars according to the number specified in the parameter.

    // Example
    print(3);
    // Should print
    * * *
    * * *
    * * *
    * * *
    * * *
    * * *
    * * *
    * * *
    * * *
    * * *

5 . Do the same as exercise 5, but now only as many lines as there's stars in each line.

    // Example
    print(3);
    // Should print
    * * *
    * * *
    * * *

    print(5);
    // Should print
    * * * * * 
    * * * * * 
    * * * * * 
    * * * * * 
    * * * * * 

6 . Print the folowing to the console using 2 for loops.

    * 
    * * 
    * * * 
    * * * * 
    * * * * * 
    * * * * * * 
    * * * * * * * 
    * * * * * * * *  
    * * * * * * * * * 
    * * * * * * * * * *

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%