• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

This build having extra unwanted lines

 
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: 65447
248
  • 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: 6186
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • 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.)
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!