• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

This build having extra unwanted lines  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/*
*Function of this build is to ask a student questions about
*school and have the answers turned into a sentence after answered.
*
*I'm getting a line that has all answers combined after the complete
*sentence is finished.
*
*/
package madlibs;
import java.util.Scanner;

public class MadLibs {
public static String major, course, instructor, restaurant, hangout,
addStatements;
public static Scanner keyboard = new Scanner(System.in);


public static void main(String[] args)
{
String combineStatements = addStatements();
System.out.println(combineStatements);
}

public static String addStatements()
{
System.out.println("What's your major?");
major = keyboard.next();

System.out.println("What's your favorite course?");
course = keyboard.next();

System.out.println("Whos your favorite instructor?");
instructor = keyboard.next();

System.out.println("What's your favorite restaurant on campus?");
restaurant = keyboard.next();

System.out.println("What's your favorite hangout place?");
hangout = keyboard.next();

addStatements = major + course + instructor + restaurant + hangout;

System.out.println("My major is " + major + " and I am taking a "
+ "class called " + course + " with the instructor called"
+ " Prof. " + instructor +
". After class, I like eating at " + restaurant + " and then"
+ " hanging out in the " + hangout);
return addStatements;

}

}
 
Marshal
Posts: 64179
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please explain what is happening, and how it differs from what you expected.
Please always post correctly indented code using the code button.
 
Sheriff
Posts: 5931
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bevance Lynch wrote:/*
*Function of this build is to ask a student questions about
*school and have the answers turned into a sentence after answered.
*
*I'm getting a line that has all answers combined after the complete
*sentence is finished.
*
*/


Well, you have a System.out.println in main() and in addStatements() so I would expect that.  Take out one of the other.  (Note: one solution is better than the other.)
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!