F Semester Java Flashcards

1
Q

How do we accept user input?

A

we go to the top and we write

import java.util.Scanner;

then we go back and write Scanner

scanner = new Scanner (System.in);

System.out.println (“Please enter your …”);

and then we store it with

String name = scanner.nextLine();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Condition for stopping while loop

A

Between ()
Example:
While (kleinerZahl!= 0) {………..
……}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Checken ob 6 eine Primzahl ist

i = 1 → 6 % 1 == 0 → sum = 1

i = 2 → 6 % 2 == 0 → sum = 1 + 2 = 3

i = 3 → 6 % 3 == 0 → sum = 3 + 3 = 6

i = 4 → 6 % 4 != 0 → skip

i = 5 → 6 % 5 != 0 → skip

A

int sum = 0;
for (int i = 1; i < 6; i++) {
if (6 % i == 0) {
sum += i;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Calculate how much time the program takes to run?

A

long begin = System.currentTimeMillis();

CODE

long end = System.currentTimeMillis();

long time= (end-begin)/1000;

System.out.println(“Elapsed Time : “ + time + “ milliseconds.”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly