• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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: 64494
225
  • 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.
 
Marshal
Posts: 5988
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.)
 
Evil is afoot. But this tiny ad is just an ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!