Ich sitze gerade im Technikum Porgrammieren und stehe total auf m Schlauch.
Wenn jemand von euch weiß wie ich folgende Aufgabe lösen kann bin ich euch echt dankbar.
Auch für Denkanstöße jeglicher Art bin ich dankbar.
Code:
class While {
// Demonstrate While loop.
public static void main ( String args[] ) {
int[] F = {90,91,92};
int i; // declare loop counter
System.out.println("Start program...");
i = 0; // initialize loop counter (= array index)
while (i <= 2) // loop variable still in range?
{
System.out.println(F[i]); // display value
i = i + 1; // increment loop counter
}
System.out.println("Program finished");
}}
Aufgabe:
2. Modify the program While to use the length property of an array.
Declare the array F to have 6 elements of type character.
3. Implement bubblesort for a character array of at least 6 elements.
Display the elements before sorting and after every change in the array.
Think about the best way to display what your program is doing.
Initialize the array appropriately to test your program.
You may use only WHILE and IF-THEN-ELSE for program control!
The loop statements FOR and DO are not allowed! VERBOTEN!
Use comments to describe what your program does.
4. Extend your bubblesort solution to count how many times the inner loop is
executed, and how many times elements are swapped.
Bis jetzt hab ich:
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bubblesort;
/**
*
* @author eulric
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char[] F = {'a','c','b','e','d','f'};
int i; // declare loop counter
System.out.println("Start program...");
i = 0; // initialize loop counter (= array index)
while (i <= 5) // loop variable still in range?
{
System.out.println(F[i]); // display value
i = i + 1; // increment loop counter
}
System.out.println("Program finished");
}
}
LG
Belenus