Scanner trouble...

Hello!
My program is supposed to determine the number of vowels in a sentence. The problem is trying to get the sentence from the user. This is the program and it's not working. The program just stops after the user input and does nothing else.
import java.util.*;
public class Main {
static String vowels = "aeiou";
public static void main(String[] args)
     Scanner sc = new Scanner(System.in);
     String something = "";
     System.out.println("Write something : ");
     do
         something += sc.next();
     while (sc.hasNext());
for (int i = 0;i<something.length(); i++)
        if (vowels.indexOf(something.charAt(i)) >= 0)
            t++;
    System.out.println("There are " + t +
            " vowels in this sentence:  ");
    System.out.println(something);
}I have also tried this:
import java.util.*;
public class Main {
static String vowels = "aeiou";
public static void main(String[] args)
     Scanner sc = new Scanner(System.in);
     String something = "";
     System.out.println("Write something : ");
     something = sc.next();
for (int i = 0;i<something.length(); i++)
        if (vowels.indexOf(something.charAt(i)) >= 0)
            t++;
    System.out.println("There are " + t +
            " vowels in this sentence:  ");
    System.out.println(something);
}but this time, if I have no vowels in the user input, I get 0, if I have one or more vowels, even if they are different, I still get only 1. Where did I go wrong?
Edited by: MissAlexa on Aug 15, 2008 5:05 AM
Edited by: MissAlexa on Aug 15, 2008 5:06 AM

For one thing your variable "t" is never declared
Changing your code to this seems to work fine for me:
     import java.util.*;
     public class Main {
     static String vowels = "aeiou";
     public static void main(String[] args)
          Scanner sc = new Scanner(System.in);
          String something = "";
          int t = 0;
          System.out.println("Write something : ");
          something = sc.next();
     for (int i = 0;i<something.length(); i++)
             if (vowels.indexOf(something.charAt(i)) >= 0)
                 t++;
         System.out.println("There are " + t +
                 " vowels in this sentence:  ");
         System.out.println(something);
     }Edited by: jnaish on Aug 15, 2008 5:44 AM

Similar Messages

  • EPson 2450 Scanner trouble

    I forgot to load the Epson scanner software, and hooled up the USB cable, and voila - to my pleansant surprise, it opened up image capture, and recognized the 2450, then "overviewed" my picture. I then selected some options, and tried to scan - no!
    To my dissappointment, it will do an overview, but it goes nowhere. The scanner button WILL NOT highlight, so I cannot scan - what is the deal!!!!????
    Thanks.

    The simplest possible explanation: Have you defined a part of the Overview to be scanned? Click and drag* over the desired portion; that has to be done before a scan is possible.
    Posting in a forum more appropriate to Image Capture (part of or bundled with the OS, and covered there) would have been a good second thing to do.
    *Reading Image Capture > Help would have revealed that step, along with the rest of the steps to take iot scan an image. A quick perusal of the Help section would have been a really good first thing to do, and would have saved us both a bit of typing.

  • Scanner trouble after mavericks download

    just downloaded mavericks and now my scanner won't scan.  it's a konica-minolta magicolor 1690-mf.  any thoughts?

    I have a similar problem with my CanoScan 9950F.  About this Mac can see the scanner, but system preferences Imaage Capture and CanoScan Toolbox 4.9 dosen't.  I've rebooted, changed Firewire cables and finally sent a message to Cannor help.
    This seems to be a multiplatform problem.
    Any thoughts?

  • New officejet 6600 - Can't scan or fax, printing A-ok. Using wireless.

    Hi I have read and tried every thread on this topic. it is now 6 hours later and about 30 restarts, installs, re-installs and re-re installs, oh and full uninstalls, each time turing off firewall and anti-virus. Microsoft paint won't work either, but the printer shows up in the windows scan and fax, but just hangs when trying to connect. I have tried HP printer and scanner trouble shooter recognizes the printer but when scan trouble is selected hangs also on drivers. What else.. umm I tried most of the help topics here... so who is up to the challange of this one. Windows 7 machine. I  had a office jet 6700 connected last week worked great at work, so bought this 6600. I thought conflict but uninstalled all hp files and reinstalled using hp installation package. Followed thread on regestry updating, and services.msc. I read about reg edit or mechanic, have used AVG reg cleaner, but disabled it for the install. 
    This question was solved.
    View Solution.

    This was posted on the forum really really works and now I can scan!
    http://www.youtube.com/watch?v=HbWpgww5I-M

  • Using Terminal

    I recently found a 3rd party driver for my old scanner that worked perfectly until the scanner was powered off. After the scanner was powered off and turned back on my mac could no longer find it. So I used the 3rd party site's trouble shooting to try to get the mac to see the scanner again using terminal. I entered this line: sudo emacs /usr/local/etc/sane.d/〈name of your backend〉.conf
    I didn't realize that I had to name my backend at the time so I left it as is. What did I tell my machine to do? Since I did that every time I boot up, the bluetooth assistant pops up looking for a wireless keyboard (I don't have one) until my keyboard is detected. Could that be related? I've gotten around the window by clicking off the bluetooth assistant at startup option in my system preferences, but I'd like to know what I've done to my baby.
    thanks

    First off, I don't think that your scanner troubles have anything to do with the bluetooth keyboard. Your scanner isn't connected with bluetooth, is it?
    The sane.d directory is for scanner-only stuff (sane stands for "Scanner Access Now Easy").
    It sounds like you have a bluetooth keyboard defined in your bluetooth preferences. If you can find it, delete it from the list.
    You didn't say if you got your scanner working again or not. You probably don't need a Terminal-based editor to manage text files. With the Finder, you can open /usr/local/etc/sane.d by selecting Go -> Go to folder and typing the path in. You may have permission issues there, so you'll probably have to enter your admin account password whenever you change anything.

  • Image Capture and Preview have trouble finding scanner. Photoshop no problem.

    Image Capture and Preview have trouble finding the scanner wirelessly unless it is on when the Mac starts up. Photoshop finds the scanner no problem. Any suggestions for Image Capture or Preview?
    The scanner is Canon MP620. Mac is MBP, running 10.8.2
    I have done all the uninstall, reinstall, update drivers, etc. Please don't bother suggesting that stuff.
    Thanks.

    As for the scanner - so is this new one wireless? When I hooked up my Epson All-in-One, I had to install it via USB first before I could install the wireless (per their instructions).  With Snow Leopard, I simply installed the driver and it covered and recognized both the print and scan function - not so in Lion; I had to go through hoops with the scanner part and it finally showed up as a separate unit. I thought that is silly, but - as long as it works.....  I'm trying to think of possibilities since I'm about out of ideas, so you might want to consider that (if it applies). The other troubleshooting suggestions usually include redoing the "add" function after a reboot.
    As for Image Capture, I am out of ideas. FWIW, I never use it - in my workflow, there is no need for it. Not sure if this would have an impact, but make sure that you choose Image Capture in the CDs&DVDs Preference Pane (mine is set to ignore or ask purposely):
    If that does not work, I'd suggest reinstalling the OS over the top of what you have.

  • Obvious power issue effecting all back plane jks. Popping HOURLY (clocked) thru speakers, lites up lamp on doc scanner. Has blown power supply once. "Genius" diag NTF twice B4 power supply blew. Still have same trouble. I made very CLEAR to Genius Ba

    Obvious power issue effecting all back plane jks. Popping HOURLY (clocked) thru speakers, lites up lamp on doc scanner. Has blown power supply once. "Genius" diag NTF twice B4 power supply blew. Still have same trouble. I made very CLEAR to Genius Bar that it was a hardware issue after they continued to trouble shoot software. I was referred to tier 2 who told me they only worked on SOFTWARE. Does anyone know a more qualified shop who can fix an OBVIOUS mother board issue tracing back to the power supply? I had the same issue with a 20" with 7 visits & had to literally take a video of the trouble before they could figure out the trouble was the video card. From reading the sheer number of posts of the same trouble descriptions going back to 2007, it's all too obvious the path to MSFT is being taken.

  • 648max USB2.0 trouble with Epson 2400 scanner

    It seems to be impossible to use an EPSON scanner Perfection 2400 Photo 2.0 with a system based on a 648max, the preview works but when you try to scan, you "loose" the signal. If you disabled the USB2.0 function in BIOS, all works OK.
    As OEM we can easily change components, so we tried with another 2 mainboards (648max and 648max-F) with the same results, the bios is update to 1.4 version.
    The operating system is WinXPHome so there is no driver update from SiS or Microsoft for USB2.0.
    The scanner with the same cables and drivers (original CD or update from Epson web) works correctly with a VIA-based (athlon) USB2.0 mainboard, so we can say that the scanner is fine.
    I'm sure there is a BIOS issue, because the 1.4 version talk about a USB ZIP trouble.
    Thanks for your urgent support.
    Pedro.

    Quote
    Originally posted by areachip
    It seems to be impossible to use an EPSON scanner Perfection 2400 Photo 2.0 with a system based on a 648max, the preview works but when you try to scan, you "loose" the signal. If you disabled the USB2.0 function in BIOS, all works OK.
    As OEM we can easily change components, so we tried with another 2 mainboards (648max and 648max-F) with the same results, the bios is update to 1.4 version.
    The operating system is WinXPHome so there is no driver update from SiS or Microsoft for USB2.0.
    Silly question, but is the version of XP Home that you  use on the 648Max upograded to SP1? I dont think XP had 2.0 functionality til then.
    Another thing you may want to try is to run the scanner through a powered hub, or even try a USB 2.0 add on card. If it works through a powered hub it may be a onboard power issue. If it works with an add-on USB 2.0 card then it may well be a BIOS or design issue.

  • Trouble with my scanner.

    After installing the new OS, I'm having trouble with my HP scanner (documents turn out solid black). What can I do?

    What software are you using with the scanner?  Have you tried Image Capture, from Finder > Applications?
    That has been working for my Epson much better than the Epson software.

  • Having trouble with the scanner

    My Code below will Display the prompt for a name (but will not allow the user to type anything) and on the next line is the prompt for hourly rate. The trouble I am having is what to put in the underlined help sections of the code. What do I have to put in Help1 to declare a Name, What should I put in help2 to get the scanner to read the Name, and what would I have to Put in Help 3 to Print the name. Any Help would be greatly appreciated.
    class PayRollApp
    //main method begins execution of Java application
    public static void main( String[] args )
    //create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );
    Help 1
    int number1; //Hourly rate
    int number2; //number of hours
    int results;// product of number1 and number 2
    System.out.print( "Enter Name:\n" );//Prompt
         Help 2     
    System.out.print( "Enter Hourly Rate: " ); //prompt
    number1 = input.nextInt(); //read first number
    System.out.print( "Enter Number of Hours:");//prompt
    number2 = input.nextInt(); // read second number
    results = number1 * number2; // multiply numbers
    System.out.printf( "Net Pay for _Help 3_ \n is $ %s\n",results);               
    } //end method main
    }// end class

    So, onedayonly24, what sorry excuse do you have for posting a fresh topic without even acknowledging the response on your prevoius thread posted just 2 days earlier?
    Or do you think you'll get lucky and someone will spoonfeed you the correct code?
    db
    Go through the tutorials at
    {color:#0000ff}http://java.sun.com/docs/books/tutorial/index.html{color}

  • Trouble with USB Printer/Scanner on Vista x64 and Airport Extreme

    I recently just purchased the Airport Extreme and set up my wireless network. I had a little trouble setting up my printer on my PC workstation, but finally realized I needed to download Bonjour for Windows 64-bit to get it working since I was using Vistax64. So now its working. However, I have an HP PSC 2510 Photosmart all-in-one printer/fax which also containes a scanner. Is there any way to get the scanner working on this for either my MacBook Pro or preferably on my Win Vista PC? I see no option to allow for this. If anyone can help or point me in the right direction, I would very much appreciate it. Thank you.

    Hello Ambien. Welcome to the Apple Discussions!
    Is there any way to get the scanner working on this for either my MacBook Pro or preferably on my Win Vista PC? I see no option to allow for this. If anyone can help or point me in the right direction, I would very much appreciate it.
    Unfortunately, none of the "advanced" functions (scanning, copying, faxing, etc.) of multi-function printers are supported by the USB port of any of the AirPort base stations.

  • Hp photosmart premium C309g-m - trouble with scanner

    I scan the image but am not able to get it off of the 'scanner' window to the computer

    Try scanning from your Mac. Use Image Capture app in your Applications folder.
    Click once on the scanner on the left side, then click on Show Details along the bottom. Along the right side you will see LOTS of options for scanning and saving.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Having trouble with scanner.hasNext()

    hey guys,
    i'm doing in assignment for which i need to use the scanner class's hasNext() method but for some reasons i'm not getting teh result i expect maybe someone could help me and explain me where my understanding is wrong, thanks i advance
    here's what i've, very simpleand basic code:
    public static void main (String[] args)
            String str = "My name is" + "\n" + "Muhammad";
            Scanner input = new Scanner(System.in);
            while (input.hasNext ()) {
                System.out.println (input.next ()); 
                System.out.println(input.hasNext ());
    If my input is this: "My name" then it should display:
    My
    true
    name
    false
    and then exit from the loop but it's not doing that instead it displays this:
    my
    true
    name and then asks for input again, then displays
    true (that's obvious bec, i feed another input)However, if i've pass a string as an paramter to scanner then it works fine. e.g.
    String str = "My name is" + "\n" + "Muhammad";
    Scanner input = new Scanner(str);
    Output:
    My
    true
    name
    true
    is
    true
    Muhammad
    falseCould someone please explain me what is the problem or where my understanding is wrong, thanks in advance!

    ok i got that but is there way to get out of the
    loop? Because what i'm eventually trying to do is
    read an input, could be mutliple lines, then do some
    manipulation. If you're reading from the keyboard--i.e., System.in--how will you, the user, signal to your program that you're done?
    * Not type anything for 30 seconds? Ick.
    * Type a special "DONE" token?
    * Enter a fixed number of lines?
    There has to be some agreed upon signal between your program and whoever/whatever is providing the input as to what it means to be "done." Decide on that, and write your code accordingly.
    There's no way to know that there are "no more tokens" on System.in, because System.in doesn't "end."

  • I Have the latest desktop computer and having trouble with image capture recognising scanner

    Has anybody got any ideas on how to get my computer to recognise my scanner

    http://www.ricoh-usa.com/downloads/popup/popup_manuals_drivers_download.aspx?pat h=http%3a%2f%2fsupport.ricoh.com%2fbb%2fhtml%2fdr_ut_e%2frc2%2fmodel%2fspc242s%2 fspc242sen.htm
    reveals this:
    Mac OS X 10.9 (OS X Mavericks)
    Description
    Version
    Update
    File size
    Download
    PPD Installer
    Ver.2.01
    12/24/2012
    55 KB
    ColorSync files
    New!
    Ver.1.0.0
    02/20/2014
    61 KB
    Twain Driver
    Ver.2.03
    12/24/2012
    5,267 KB
    The TWAIN driver is the scanner driver.  Combined with Apple's Ricoh download, it should work.  Otherwise you need to contact Ricoh and ask why it isn't.

  • Trouble recognizing scanner when Officejet Pro is on network connection. iMac with OS X 10.8

    I am considering replacing my Officejet Pro 8500 because the scanner is not recognized when the device on connected on the network.  Printer is recognized and works fine, but scanner is not recognized from my iMac (OSX 10.8.2).  I have the latest HP software driver installed.
    However, the printer AND scanner work fine from another iMac (OSC 10.6) on the same network.
    Is there a problem with the driver when running under OSX 10.8?  Could it be that the driver is not installed correctly in the iMac running OSX 10.8 (I've installed the new driver twice).  Could this be resolved by returning the 8500 printer (covered under 3rd party warranty) and buying an Officejet Pro 8600?
    This question was solved.
    View Solution.

    AMacGuy ...
    Thanks for the reply.  The printer is the A910 version.
    I am trying to scan from either the HP utility or from the Mac <system preferences> <Print & Scan> function.  
    When using the HP scan app, the scanner is not recognized.  When using the Print/Scan function in System Preferences, the little window that comes up shows the HP Officejet Pro 8500 A910, but there is no Print/Scan tab at the top.  
    The printer works fine.  The scanning funcction will not work (initiated from the Mac), whether connected by wireless or ethernet.  When the printer is installed by USB cable, it works fine (print and scan functions).
    Note: Connected on the network, if I access the printer by typing the local IP address in the web browser, both the print and scan functions work fine.  Also, the print AND scan functions work fine from another iMac on the network - this iMac (my wife's) is running OS X 10.6, Snow Leopard.
    I have talked to an Apple Care supervisor (very helpful), and we have uninstalled all HP drivers and apps, repaired disk permissions, removed all HP software using Disk Utility, then re-installed the HP driver pack from hp.com.  
    The problem seems to be due to OSX 10.8 and the drivers on the OSX 10.8 Mac when the printer is connected by network (wireless or ethernet).
    Any ideas?  I have been authorized by a 3rd party warranty service (through Office Depot) to return the printer for a refund (now almost 2 yrs old).  Should I just return the printer and buy an Officejet 8600, or would this just have the same problem?   I have also considered switching to an Epson WF 3540, just in case the problem is with HP's driver software.  
    Any ideas before I just return the printer to the warranty company?
    Thanks.

Maybe you are looking for