Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package texto;
- import java.util.Scanner;
- public class Texto {
- static void guion(String texto){
- for(int i = 0; i < texto.length(); i++){
- System.out.print("-");
- }
- System.out.println("");
- }
- static int num_palabras(String texto){
- int c = 1;
- char a[] = new char[texto.length()];
- for(int i = 0; i < texto.length(); i++){
- a[i] = texto.charAt(i);
- if(a[i]==' '){
- c++;
- }
- }
- return c;
- }
- static void pal_separ(String texto){
- char a[] = new char[texto.length()];
- for(int i = 0; i < texto.length(); i++){
- a[i] = texto.charAt(i);
- if(a[i]!=' ')
- System.out.print(a[i]);
- else
- System.out.println("");
- }
- System.out.println("");
- }
- static int comp(String str,String texto){
- int c = 0;
- char s = str.charAt(0);
- char a[] = new char[texto.length()];
- for(int i = 0; i < texto.length(); i++){
- a[i] = texto.charAt(i);
- if(a[i]==s){
- c++;
- }
- }
- return c;
- }
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- String str;
- boolean f = false;
- System.out.println("Digite un texto o palabra");
- str = s.nextLine();
- char a[] = new char[str.length()];
- for(int i = 0; i < str.length(); i++){
- a[i] = str.charAt(i);
- if(a[i]==' '){
- f = true; //texto
- break;
- }
- else{
- f = false; // palabra
- }
- }
- if(f){
- System.out.println("Digito un texto");
- System.out.println("El numero de palabras es "+num_palabras(str));
- System.out.println("Las palabras presentes en el texto son:");
- pal_separ(str);
- int n = 0;
- do{
- System.out.println("Digite una letra:");
- String ch = s.next();
- if(comp(ch,str)==0){
- n++;
- System.out.println("La letra no esta presente");
- }
- else
- System.out.println("La letra "+ch+" aparece "+comp(ch,str)+ " veces.");
- }
- while(n!=2);
- }
- else{
- System.out.println("Digito una palabra");
- System.out.println("Guiones por cada letra:");
- guion(str);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement