Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
word switcher porlebm
Jesse Crockett
Ranch Hand
Posts: 129
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Wath's wnorg hree?
// first run text random word switch import java.io.*; import java.util.*; public class Generator { static final String text = "so much depends " + "on a red wheelbarrow " + "glazed with rain water " + "beside the chickens"; static String word, output = "/*** "; public static void main(String[] args) throws FileNotFoundException { String type; Scanner srchVT, srchVI, srchN, srchA; Scanner txt = new Scanner(text); Scanner con = new Scanner(System.in); int a, b, c, d; while(txt.hasNext()) { word = txt.next(); System.out.print(word + " : "); System.out.print("enter type to import ( 'v', 'n', 'a' or '/' to skip ) : "); type = con.next(); // input type of word to import System.out.println(); if (type.equals("/")) { // don't switch the word System.out.println("skipping word"); } else if (type.equals("v")) { // import v System.out.println("switching with verb"); if((int)Math.random() * 10 != 0) { // import vt srchVT = new Scanner(new FileReader("vt.set")); a = (int)Math.random() * 18391; //vt.set count + 1, &c. for(int i = 0; i < a; i++) word = srchVT.next(); srchVT.close(); srchVT = null; } else {// import vi srchVI = new Scanner(new FileReader("vi.set")); b = (int)Math.random() * 7231; for(int j = 0; j < b; j++) word = srchVI.next(); srchVI.close(); srchVI = null; }// vt / vi transfer } else if(type.equals("n")) {// import n System.out.println("switching with noun"); srchN = new Scanner(new FileReader("n.set")); c = (int)Math.random() * 879234; for(int k = 0; k < c; k++) word = srchN.next(); srchN.close(); srchN = null; } else if(type.equals("a")) {// import a System.out.println("switching with adjective"); srchA = new Scanner(new FileReader("a.set")); d = (int)Math.random() * 35348; for(int ii = 0; ii < d; ii++) word = srchA.next(); srchA.close(); srchA = null; } else System.out.println("skipping word"); output += word + " "; }// while System.out.println(output); }// main }// Generate
(.set files are ok)
Jesse Crockett
Ranch Hand
Posts: 129
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I solved it by using arrays and populating them before going into the rest of it
BWA HA HA HA HA HA HA! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
June Newsletter Puzzle
Changing array I think and the print statement
StringBuffer class
need help with applet ActionListener
Unusual behavior of Simple Cipher Program
More...