logo
down
shadow

Removing vowels from an input string using a loop


Removing vowels from an input string using a loop

By : Tomislav Tumbas
Date : November 21 2020, 03:00 PM
it helps some times I'm very much in favor of using a while loop for this, but since you stated you can only use a for loop...
The problem is that your loop will iterate until i = 5, even if a vowel is detected. We need a way to tell the loop to pretend that never happened. You can't decrement i, or you'll be stuck at the same character forever.
code :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);
    String s = "";
    System.out.println("Type a tweet: ");
    String input = keyboard.nextLine();
    int f = 0;
    int tweetLengthAllowed = 5;
    for(int i = 0; i < tweetLengthAllowed; ++i) { //Must be a for loop
        char c = input.charAt(i);

        if(c == 'a'|| c == 'e'|| c == 'i'|| c == 'o'|| c =='u' || 
            c == 'A' || c == 'E' ||  c == 'I' ||  c == 'O' || c == 'U') {

            f = 1;
            tweetLengthAllowed++; //Allows the loop to continue for one more interation
        } //end if
        else{
            s = s += c;
            f = 0;
        }//end else
    } //end for
    System.out.println(s);

} //end main
} //end class


Share : facebook icon twitter icon
MIPS assembly - removing vowels from an input string

MIPS assembly - removing vowels from an input string


By : Brad Vaile
Date : March 29 2020, 07:55 AM
seems to work fine So. I took a look at what you've writen and I've fixed it.
My first thought is I don't know what you are doing with the stack and stack pointer ($sp). It didn't seem necessary so I took it out.
code :
    .text
    .globl  main

main:
    # display prompt
    li      $v0, 4
    la      $a0, prompt
    syscall
    # accept input string
    li      $v0, 8
    la      $a0, str
    li      $a1, 82
    syscall

    li      $t1, 0          # initiate index
    li      $t3, 0          # vowel count

poploop:
    lb $t0 str($t1)

    # check if vowel
    li      $t2, 'a'       # a
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'e'       # e
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'i'       # i
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'o'       # o
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'u'       # u
    beq     $t0, $t2, vowel
    nop

    # if not a vowel, store it at current index in string less vowel count
    sub     $t2, $t1, $t3
    sb      $t0, str($t2)
    j       next
    nop
vowel:  # if vowel, inc count
    addi $t3, $t3, 1
next:
    addi $t1, $t1, 1

    beqz    $t0, done       # once we reach null char, finish
    nop
    j       poploop
    nop

done:   
    li      $v0, 4
    la      $a0, str
    syscall
    li      $v0, 10         # exit program
    syscall
    nop

    .data
str:    .space 82
prompt: .asciiz "Input a string:\n"
Removing all the vowels from a string - PL/SQL

Removing all the vowels from a string - PL/SQL


By : user3211887
Date : March 29 2020, 07:55 AM
To fix this issue Technically, the assignment calls for an anonymous pl/sql block, and prompting user for input. So you'd have something like this:
code :
set serveroutput on
set verify off

accept vstring prompt "Please enter your string: ";
declare
   vnewstring varchar2(100);
begin
   vnewstring := regexp_replace('&vstring', '[aeiouAEIOU]','');
   dbms_output.put_line('The new string is: ' || vnewstring);
end;
/
Please enter your string: This is a test
The new string is: Ths s  tst

PL/SQL procedure successfully completed.
counting the vowels, without using raw input and the string 's' is defined.My result a infinite loop, whats wrong in it

counting the vowels, without using raw input and the string 's' is defined.My result a infinite loop, whats wrong in it


By : Elliana Rochelle Lop
Date : March 29 2020, 07:55 AM
I wish this help you simply use for loop to iterate every character from the string.
Demo:
code :
In [28]: s = "qazxswedcvfrgbnhyujmkiopl"

In [29]: count = 0

In [30]: for i in s:
   ....:     if i.lower() in ["a", "i", "o", "u", "e"]:
   ....:         count += 1
   ....:         

In [31]: print count
5
Removing from vowels from a string

Removing from vowels from a string


By : heinz_ho
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Here is the code I have:
code :
[character for character in sentence if character not in vowels] # returns list
''.join([character for character in sentence if character not in vowels]) # returns string without vowels
C program to accept a string input and print number of vowels and most repeated vowels in the string

C program to accept a string input and print number of vowels and most repeated vowels in the string


By : Anthony Poujouanine
Date : March 29 2020, 07:55 AM
hop of those help? You can try any of the below approach ...
Create a struct MAP with key and value as members. Have helper methods that allow you to populate MAP struct with key as vowel and value as no. of occurrences. Create a 2D array of vowel where row represents the vowels and column no. of occurrences. Simplest to understand would be creating an array of size 256 (ascii) and keep on increment the value at array[ascii(vowel)] by 1 on each occurrence.
code :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX 150

    int NumberOfVowels(char Statement[], char vowels[], int counts[])
    {
        int i, j = 0;

        for(j=0; j<strlen(Statement); j++) {
            if (Statement[j] == '\0' || Statement[j] == '\n') {
                continue;
            }
            for(i=0; i<5; i++) {
                if(vowels[i] == Statement[j]) {
                    int ascii = (int) vowels[i];
                    counts[ascii] = counts[ascii] + 1;
                }
            }
        }

        for(i=0; i<5; i++) {
            int ascii = (int) vowels[i];
            printf("%c - %d ", vowels[i], counts[ascii]);
        }
        printf("\n");
        return 0;
    }

int main()
{
    char Statement[MAX];
    char vowels[] = {'a', 'e', 'i', 'o', 'u'};
    int counts[256] = {0};
    int i, j;

    puts("Enter a simple statement.");
    fgets(Statement, 150, stdin);
    printf("\nYou entered: %s\n", Statement);
    for(i=0; i<=strlen(Statement); i++){
        //Converting uppercase input to lowercase
        Statement[i] = tolower((unsigned char)Statement[i]);
        printf("%c ", Statement[i]);
    }
    //Calling the function to print no. of 
    NumberOfVowels(Statement, vowels, counts);
    return 0;
}
You entered: Hello How are you, I am fine!                                                                                                                           

h e l l o   h o w   a r e   y o u ,   i   a m   f i n e !    

  a - 2 e - 3 i - 2 o - 3 u - 1  
Related Posts Related Posts :
  • How Remove Recycler Separator/divider programmatically or using xml property
  • Not Able to Save Data Hibernate
  • Toolbar addView not working
  • Freeing memory wrapped with NewDirectByteBuffer
  • Synchronization with implicitwait() do not work, why?
  • Wrapper around Java primitive types
  • ClassNotFoundException: spark.Request when running from command line
  • Exception in Hibernate Configuration
  • How can I validate XML embedded in JSON using Citrus framework?
  • How is the String value passed to the updateText() method?
  • Memory efficient replace functions
  • Upload Photo with onActivityResult, but without Fullscreen capturing
  • Docker: Java 8 installation failing on Ubuntu
  • Java Netbeans Calculator performing wrong calculation
  • Nifi: Threads in nifi
  • While loop Int return inside the method completely dead
  • Checking if a user's entry is an integer using try catch statements
  • Forcing a subclass to provide an initialization method
  • calling a fuction and variables from another class in java
  • which versions of ssl and tls can we use for java 1.2
  • In spring-boot, is it possible to get properties without being a spring bean?
  • Java - Thread.join( ) does not release the lock
  • It reads the file but it is not printing it properly when it sends it to a new file?
  • Date picker Not Working on API 26
  • When does JPA persistence context end?
  • How to make Circle with Four Color in Java
  • java. inheritance/polymorphism, quiz error?
  • Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.io.Files.newReaderSupplier(Ljava/io/
  • How to convert a cURL call into a Java URLConnection call
  • Creating Substrings in a while loop
  • Java DateTimeFormatterBuilder with Verbose Time Zone
  • Memory leak using Stringbuilder in java
  • java string with English and Chinese text
  • How do I cast an array of doubles into an array of integers in Java?
  • Pair a bluetooth device in Android Studio
  • expected android.widget.textview but found java.lang.string
  • How to sort out by index(0) alphabelically or index(2) of the List<String> in the ArrayList<List<String>&
  • Creating a Drop Down Menu Bar in Java GUI
  • Java Regular expression - Pattern matching on a pipe-delimited string
  • How can i use blob storage from an azure function in Java
  • sorting numbers from a .txt doc into different category with if statements and loops
  • Creating a Search Button (Double cannot converted to String)
  • Spring Initializr Basic Project Won't Build
  • OpenCV error JAVA NETBEANS
  • How can I correctly map my classes (getting mappedBy reference an unknown target entity property)
  • RIght click JPopupMenu on JTabbedPane
  • java and reading from .txt files
  • Getting 404 error from https://ml.nexosis.com/v1/ in browser
  • Java - Eclipse Compiler Compliance Level 1.6 not working as expected
  • Autowire specific inner bean in Spring
  • How to Serialize an Attribute but dont persist it using spring data?
  • variables reverting to default value
  • How to make a JSP function to run only when called?
  • Merge str value in Hadoop Reducer
  • Connection refused from client to server
  • Apache Shiro - Assign role to groups with same prefix
  • Android Studio - DatePicker in AlertDialog, null object reference
  • What is the solution for Mass Assignment: Insecure Binder Configuration Vulnerability?
  • Cannot get update query to work with Hibernate
  • How do you add the value of one integer to another?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org