Java :: Aufgabe #23

10 Lösungen Lösungen öffentlich

Programmier-Basics: Eingabezähler

Anfänger - Java von Freki - 27.12.2012 um 15:01 Uhr
Schreiben Sie ein Programm, das ein Wort einliest. Das Wort wird dann so oft ausgegeben, wie es Buchstaben hat:

Konsolenausgabe:

Geben Sie ein Wort ein:
Hello

Hello
Hello
Hello
Hello
Hello

Lösungen:

vote_ok
von 0 (0 Punkte) - 30.07.2013 um 17:06 Uhr
Main.java
Quellcode ausblenden Java-Code
package de.trainyourprogrammer.java23;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Request and check an order.
 * 
 * @author jsb
 */
public class Main {

	/**
	 * Execute the program.
	 * 
	 * @param args
	 *            Is ignored in our case.
	 */
	public static void main(String[] args) {
		BufferedReader buffer = new BufferedReader(new InputStreamReader(
				System.in)); // start reading from the default input

		System.out.println("Geben Sie ein Wort ein:"); // request a word

		try { // try to...
			String word = buffer.readLine(); // read word
			System.out.println(); // print empty line

			for (int i = 0; i < word.length(); i++) { // for each character in
														// the word
				System.out.println(word); // print the word
			}
		} catch (IOException e) { // ignore occurring IOExceptions
		} finally { // on quit...
			try { // try to...
				buffer.close(); // stop reading the input
			} catch (IOException e) { // again ignore occurringIOExceptions
			}
		}
	}
}
2x
vote_ok
von freak54 (170 Punkte) - 05.10.2013 um 13:52 Uhr
Quellcode ausblenden Java-Code
import java.util.Scanner;


public class Eingabezähler {
	 private Scanner S;
	 private String eingabe;
	
	public Eingabezähler(){
		S = new Scanner(System.in);
		System.out.println("Bitte Wort eingeben");
		eingabe= S.next();
		for(int i=0;i<eingabe.length();i++){
			System.out.println(eingabe);
		}
	}
	public static void main(String[] args){
		new Eingabezähler();
	}
	
}
vote_ok
von PTPHard (540 Punkte) - 29.05.2014 um 18:40 Uhr
Quellcode ausblenden Java-Code
public class Eingabezaehler
{
    
    public void output(String word)
    {
        int length = word.length();
        for(int i = 0; i < length; i++)
        {
            System.out.println(word);
        }
    }
}
vote_ok
von ElPapito (2690 Punkte) - 08.05.2015 um 20:28 Uhr
Quellcode ausblenden Java-Code

/**
 * @author ElPapito
 * @date 08.05.2015
 */

import java.util.Scanner;

public class Eingabezaehler {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.print("Geben Sie ein Wort ein: ");
		String input = scanner.nextLine();
		scanner.close();
		System.out.println();

		for (int i = 0; i < input.length(); i++) {
			System.out.println(input);
		}
	}

}

vote_ok
von Bufkin (1410 Punkte) - 18.09.2017 um 16:02 Uhr
Quellcode ausblenden Java-Code
import java.util.Scanner;

class eingabeZaehler
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner reader = new Scanner(System.in);
        String eingabe = reader.next();
        reader.close();
        System.out.println("Eingabe: " + eingabe + "\n");
        for(int i = eingabe.length(); i > 0; i--)
        {
            System.out.println(eingabe);
        }
    }
}
vote_ok
von nxko (100 Punkte) - 06.10.2017 um 12:17 Uhr
Quellcode ausblenden Java-Code

import java.util.Scanner;

public class Eingabezaehler {
	
	public static void main (String[]args) {
		
		System.out.println("Geben Sie ein Wort ein:");
		
		Scanner input = new Scanner(System.in);
		
		String sc = input.next();
		
		for (int i = 0; i < sc.length(); i++) {
			System.out.println(sc);
		}
	}

}
vote_ok
von nOrdan (1160 Punkte) - 02.06.2019 um 23:13 Uhr
Anmerkung: Ich arbeite mit dem Programm BlueJ

Quellcode ausblenden Java-Code


import javax.swing.JOptionPane;

/**
 * Das vom User eingegebene Wort wird so oft ausgegeben wie es Buchstaben hat.
 * 
 * @author (nOrdan) 
 * @version (02.06.2019)
 */
public class Eingabezähler
{
    public static void main(String [] args)
    {
        Eingabezähler e = new Eingabezähler();
        e.input();
    }

    private void input()
    {
        boolean valid1 = false;
        String input1 = "";
        konsoleLeeren();
        while (valid1 == false)
        {
            input1 = userInput("Geben sie ein Wort oder einen Satz ein");
            errorUserInput(input1);           
            valid1 = true;
        }
        output(input1);
    }

    private void output(String input)
    {       
        for (int i = 0; i < input.length(); i++)
        {
            System.out.println(input);
        }
    }

    private String userInput(String message)
    {
        return JOptionPane.showInputDialog(message);
    }

    private void errorUserInput(String input)
    {
        if (input == null) 
        {
            System.exit(0); //Drückt der User auf abbrechen wird null zurück gegeben und das Programm wird beendet
        }
        else if (input.length() == 0)
        {
            System.out.println("Da sie nichts eingegeben haben wird auch nichts ausgegeben.");
        }
    }   
    
    private void konsoleLeeren()
    {
        System.out.print('\u000C');
    }
}


vote_ok
von paddlboot (3970 Punkte) - 09.07.2019 um 09:38 Uhr
Quellcode ausblenden Java-Code
import java.util.*;

public class Eingabezähler {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		String eingabe;
		System.out.print("Geben Sie ein Wort ein:\t");
		eingabe = scanner.next();
		
		for(int i = 0; i < eingabe.length(); i++) {
			System.out.println(eingabe);
		}
		
		scanner.close();
	}
}
vote_ok
von kollar (340 Punkte) - 18.12.2019 um 22:55 Uhr
Quellcode ausblenden Java-Code
import java.util.Scanner;

public class EingabeZaehler {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String stEingabe;

		System.out.println("Geben Sie ein Wort ein:");
		stEingabe = scan.nextLine();
		System.out.println();
		for (int i = 0; i < stEingabe.length(); i++) {
			System.out.println(stEingabe);
		}
	}
}
vote_ok
von 0 (0 Punkte) - 10.04.2021 um 21:56 Uhr
Quellcode ausblenden Java-Code
import java.util.Scanner;

public class ProgrammierBasicsEingabezaehler {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.println("Geben sie ein Wort ein:");

        String wort = scanner.nextLine();

        System.out.println(" ");

        for (int i = 0; i < wort.length(); i++) {
            System.out.println(wort);
        }

    }

}