using java
LO: (Remember) Students will recall how to read from standard input.
LO: (Apply) Students will write loops that iterate as long as a condition is true.
Write a program that reads words from standard input and displays them to standard output. When the word "end" is read, print it out and then stop reading input.
starter code:
import java.util.Scanner;
/*
* Reads and displays words from standard input until hitting a stop
word.
*/
public class WhileLoop {
public static void main(String[] args) {
}
System.exit(0);
}
import java.util.Scanner; /* * Reads and displays words from standard input until hitting a stop word. */ public class WhileLoop { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String word; System.out.print("Enter word: "); word = scan.nextLine(); while(!word.equals("end")){ System.out.println(word); System.out.print("Enter word: "); word = scan.nextLine(); } } }
Get Answers For Free
Most questions answered within 1 hours.