0

Okay so I have to have write a program that takes website names until you type stop.
After that it should count how many websites were entered.

package website;

/**
 *
 * @author 
 */
import java.*;
import java.util.Scanner;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      int com = 0;
     

      //It'll catch the website name here
      System.out.println("Please enter a website name: ");
      String url = scan.next();

      int dotCom = url.indexOf(".com");
      int stop = url.indexOf("stop");
      
      while(!url.equals(stop))
      {
         if ( dotCom > 0)
         com = com + 1;
         System.out.println(com);
        
         if (stop > 0)
         {
             System.out.println(com);
             break;
          }
          }
           
        
           
    }

}

Right now it just adds numbers and doesn't stop after you enter in a domain name.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by kramerd
0

1. You can use a do...while loop, rather than a while loop so you check the condition at the end of the loop instead of at the beginning.
2. You should put everything from the prompt to enter the website on inside the loop.
3. Think about what the condition should be for exiting the loop.
4. After the loop ends, that's when you should print out the number of websites you read in.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.