• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:51
CEST 15:51
KST 22:51
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris32Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
Greatest Players of All Time: 2025 Update #1: Maru - Greatest Players of All Time A Eulogy for the Six Pool Geoff 'iNcontroL' Robinson has passed away #2: Serral - Greatest Players of All Time
Tourneys
Esports World Cup 2025 Maestros of The Game—$20k event w/ live finals in Paris Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
No Rain in ASL20? BW General Discussion Post ASL20 Ro24 discussion. BSL Polish World Championship 2025 20-21 September BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL20] Ro24 Group F [Megathread] Daily Proleagues [ASL20] Ro24 Group E [IPSL] CSLAN Review and CSLPRO Reimagined!
Strategy
Muta micro map competition Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2196 users

The Big Programming Thread - Page 206

Forum Index > General Forum
Post a Reply
Prev 1 204 205 206 207 208 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
November 30 2012 13:43 GMT
#4101
On November 30 2012 22:14 Morfildur wrote:
Show nested quote +
On November 30 2012 20:49 icystorage wrote:
I'm sorry guys but this is kind of a homework problem and got stuck.
im not really good in Java but how do you fix this problem?

+ Show Spoiler +
[image loading]


the scanner totally skips the 'Enter Student Name' part and directly proceeds to the Enter Student Id.

Did I do something wrong?

the x = null; part is just a hunch coz i thought x wasn't initialized properly.

+ Show Spoiler +
import java.util.Scanner;


public class Driver {


public static void main(String[] args) {

int choice, numberCourses, y;
String x;
Scanner input = new Scanner(System.in);
boolean loop = true;

while(loop == true){

System.out.println("Student Record Menu");
System.out.println("[1] New Record");
System.out.println("[2] Display Records");
System.out.println("[3] Quit");

choice = input.nextInt();

switch(choice) {
case 1:
System.out.println("New Record:");
Record record = new Record();
record.createStudent();

System.out.println("Enter Student Name:");
x = null;
x = input.nextLine();
record.setName(x);

System.out.println("Enter Student ID:");
x = input.nextLine();
record.setId(x);

System.out.println("Enter Course:");
x = input.nextLine();
record.setCourse(x);

System.out.println("Enter number of Subjects:");
numberCourses = input.nextInt();

for (int i = 1; i < numberCourses; i++) {
Course course = new Course();
System.out.println("For Subject " + i);
System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
System.out.println("Enter Description:");
x = input.nextLine();
course.setDesc(x);
System.out.println("Enter Subject Units:");
y = input.nextInt();
course.setUnits(y);
System.out.println("Enter Grade:");
y = input.nextInt();
course.setGrade(y);
record.addCourse(course);
}
System.out.println("Done Adding...");
case 2:
case 3:
loop = false;
}
}

}

}


the entire Driver code.


A simple google search for "java nextLine skips" gave me the correct solution so i suggest next time you'll just try googling it first.

As opposed to what you might expect from a method called "nextLine", it doesn't return the whole line but only the part until the EOL characters (basically the enter key). You have to call another input.nextLine() after reading each line, i.e.:


System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
input.nextLine(); // <-- don't need to store output

...



Eh imo the nextLine() method works exactly as you'd expect. It returns all the characters till the next newline character. If it didn't behave this way, you'd end up wondering what happens with a call to nextLine() after something like a call to nextInt().

E.g. if the input were //this is your problem icystorage
1\n //or \r\n
Next line\n

and you call nextInt() to advance to scanner beyond 1 - what should nextLine() return? It should be the empty string, because otherwise that character just gets lost.

I mean if the input were

1 2\n
Next line\n

And you called nextInt() than nextLine(), you'd expect nextLine() to return 2 otherwise it'd be even more confusing.
RIP GOMTV. RIP PROLEAGUE.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
November 30 2012 14:01 GMT
#4102
On November 30 2012 22:43 teamamerica wrote:
Show nested quote +
On November 30 2012 22:14 Morfildur wrote:
On November 30 2012 20:49 icystorage wrote:
I'm sorry guys but this is kind of a homework problem and got stuck.
im not really good in Java but how do you fix this problem?

+ Show Spoiler +
[image loading]


the scanner totally skips the 'Enter Student Name' part and directly proceeds to the Enter Student Id.

Did I do something wrong?

the x = null; part is just a hunch coz i thought x wasn't initialized properly.

+ Show Spoiler +
import java.util.Scanner;


public class Driver {


public static void main(String[] args) {

int choice, numberCourses, y;
String x;
Scanner input = new Scanner(System.in);
boolean loop = true;

while(loop == true){

System.out.println("Student Record Menu");
System.out.println("[1] New Record");
System.out.println("[2] Display Records");
System.out.println("[3] Quit");

choice = input.nextInt();

switch(choice) {
case 1:
System.out.println("New Record:");
Record record = new Record();
record.createStudent();

System.out.println("Enter Student Name:");
x = null;
x = input.nextLine();
record.setName(x);

System.out.println("Enter Student ID:");
x = input.nextLine();
record.setId(x);

System.out.println("Enter Course:");
x = input.nextLine();
record.setCourse(x);

System.out.println("Enter number of Subjects:");
numberCourses = input.nextInt();

for (int i = 1; i < numberCourses; i++) {
Course course = new Course();
System.out.println("For Subject " + i);
System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
System.out.println("Enter Description:");
x = input.nextLine();
course.setDesc(x);
System.out.println("Enter Subject Units:");
y = input.nextInt();
course.setUnits(y);
System.out.println("Enter Grade:");
y = input.nextInt();
course.setGrade(y);
record.addCourse(course);
}
System.out.println("Done Adding...");
case 2:
case 3:
loop = false;
}
}

}

}


the entire Driver code.


A simple google search for "java nextLine skips" gave me the correct solution so i suggest next time you'll just try googling it first.

As opposed to what you might expect from a method called "nextLine", it doesn't return the whole line but only the part until the EOL characters (basically the enter key). You have to call another input.nextLine() after reading each line, i.e.:


System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
input.nextLine(); // <-- don't need to store output

...



Eh imo the nextLine() method works exactly as you'd expect. It returns all the characters till the next newline character. If it didn't behave this way, you'd end up wondering what happens with a call to nextLine() after something like a call to nextInt().

E.g. if the input were //this is your problem icystorage
1\n //or \r\n
Next line\n

and you call nextInt() to advance to scanner beyond 1 - what should nextLine() return? It should be the empty string, because otherwise that character just gets lost.

I mean if the input were

1 2\n
Next line\n

And you called nextInt() than nextLine(), you'd expect nextLine() to return 2 otherwise it'd be even more confusing.


Well, my definition of "Line" includes the line ending as part of the line. From the first character in the buffer until and including the \n|\r\n. After a call to nextInt, the call to nextLine should from my point of view return just the \n|\r\n. That is why i would expect nextLine to return everything, not needing another call to nextLine to finish the line i requested in the previous nextLine and forcing programmers to use nextLine twice for each line.

However, it's the same behaviour in Java as in C, so i know that it's common to do it the way Java has implemented it but i still don't agree with it... though there are lots of language design decisions in all programming languages that i don't agree with, so it's just a minor point
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
November 30 2012 14:18 GMT
#4103
thanks for the replies guys

@Morfildur
I'm sorry, i only go to TL as a last resort. it's my first time encountering this problem and seriously, it didn't enter my mind what the proper keywords were for a google search. sorry and thank you!
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
teamamerica
Profile Blog Joined July 2010
United States958 Posts
November 30 2012 15:05 GMT
#4104
On November 30 2012 23:01 Morfildur wrote:
Show nested quote +
On November 30 2012 22:43 teamamerica wrote:
On November 30 2012 22:14 Morfildur wrote:
On November 30 2012 20:49 icystorage wrote:
I'm sorry guys but this is kind of a homework problem and got stuck.
im not really good in Java but how do you fix this problem?

+ Show Spoiler +
[image loading]


the scanner totally skips the 'Enter Student Name' part and directly proceeds to the Enter Student Id.

Did I do something wrong?

the x = null; part is just a hunch coz i thought x wasn't initialized properly.

+ Show Spoiler +
import java.util.Scanner;


public class Driver {


public static void main(String[] args) {

int choice, numberCourses, y;
String x;
Scanner input = new Scanner(System.in);
boolean loop = true;

while(loop == true){

System.out.println("Student Record Menu");
System.out.println("[1] New Record");
System.out.println("[2] Display Records");
System.out.println("[3] Quit");

choice = input.nextInt();

switch(choice) {
case 1:
System.out.println("New Record:");
Record record = new Record();
record.createStudent();

System.out.println("Enter Student Name:");
x = null;
x = input.nextLine();
record.setName(x);

System.out.println("Enter Student ID:");
x = input.nextLine();
record.setId(x);

System.out.println("Enter Course:");
x = input.nextLine();
record.setCourse(x);

System.out.println("Enter number of Subjects:");
numberCourses = input.nextInt();

for (int i = 1; i < numberCourses; i++) {
Course course = new Course();
System.out.println("For Subject " + i);
System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
System.out.println("Enter Description:");
x = input.nextLine();
course.setDesc(x);
System.out.println("Enter Subject Units:");
y = input.nextInt();
course.setUnits(y);
System.out.println("Enter Grade:");
y = input.nextInt();
course.setGrade(y);
record.addCourse(course);
}
System.out.println("Done Adding...");
case 2:
case 3:
loop = false;
}
}

}

}


the entire Driver code.


A simple google search for "java nextLine skips" gave me the correct solution so i suggest next time you'll just try googling it first.

As opposed to what you might expect from a method called "nextLine", it doesn't return the whole line but only the part until the EOL characters (basically the enter key). You have to call another input.nextLine() after reading each line, i.e.:


System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
input.nextLine(); // <-- don't need to store output

...



Eh imo the nextLine() method works exactly as you'd expect. It returns all the characters till the next newline character. If it didn't behave this way, you'd end up wondering what happens with a call to nextLine() after something like a call to nextInt().

E.g. if the input were //this is your problem icystorage
1\n //or \r\n
Next line\n

and you call nextInt() to advance to scanner beyond 1 - what should nextLine() return? It should be the empty string, because otherwise that character just gets lost.

I mean if the input were

1 2\n
Next line\n

And you called nextInt() than nextLine(), you'd expect nextLine() to return 2 otherwise it'd be even more confusing.


Well, my definition of "Line" includes the line ending as part of the line. From the first character in the buffer until and including the \n|\r\n. After a call to nextInt, the call to nextLine should from my point of view return just the \n|\r\n. That is why i would expect nextLine to return everything, not needing another call to nextLine to finish the line i requested in the previous nextLine and forcing programmers to use nextLine twice for each line.

However, it's the same behaviour in Java as in C, so i know that it's common to do it the way Java has implemented it but i still don't agree with it... though there are lots of language design decisions in all programming languages that i don't agree with, so it's just a minor point


Wait I don't get what you said - doesn't nextLine() behave the way you'd expect it to? Minus the fact it actually strips the new line characters, it does return all the characters in the buffer until the next new line character (in this case, there are no characters in the buffer till that newline). I'm a little confused as to how this wouldn't require a 2nd call to nextLine().

I'm sure I'm just missing your point so I'd appreciate if you could clarify.
RIP GOMTV. RIP PROLEAGUE.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
November 30 2012 16:51 GMT
#4105
On December 01 2012 00:05 teamamerica wrote:
Show nested quote +
On November 30 2012 23:01 Morfildur wrote:
On November 30 2012 22:43 teamamerica wrote:
On November 30 2012 22:14 Morfildur wrote:
On November 30 2012 20:49 icystorage wrote:
I'm sorry guys but this is kind of a homework problem and got stuck.
im not really good in Java but how do you fix this problem?

+ Show Spoiler +
[image loading]


the scanner totally skips the 'Enter Student Name' part and directly proceeds to the Enter Student Id.

Did I do something wrong?

the x = null; part is just a hunch coz i thought x wasn't initialized properly.

+ Show Spoiler +
import java.util.Scanner;


public class Driver {


public static void main(String[] args) {

int choice, numberCourses, y;
String x;
Scanner input = new Scanner(System.in);
boolean loop = true;

while(loop == true){

System.out.println("Student Record Menu");
System.out.println("[1] New Record");
System.out.println("[2] Display Records");
System.out.println("[3] Quit");

choice = input.nextInt();

switch(choice) {
case 1:
System.out.println("New Record:");
Record record = new Record();
record.createStudent();

System.out.println("Enter Student Name:");
x = null;
x = input.nextLine();
record.setName(x);

System.out.println("Enter Student ID:");
x = input.nextLine();
record.setId(x);

System.out.println("Enter Course:");
x = input.nextLine();
record.setCourse(x);

System.out.println("Enter number of Subjects:");
numberCourses = input.nextInt();

for (int i = 1; i < numberCourses; i++) {
Course course = new Course();
System.out.println("For Subject " + i);
System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
System.out.println("Enter Description:");
x = input.nextLine();
course.setDesc(x);
System.out.println("Enter Subject Units:");
y = input.nextInt();
course.setUnits(y);
System.out.println("Enter Grade:");
y = input.nextInt();
course.setGrade(y);
record.addCourse(course);
}
System.out.println("Done Adding...");
case 2:
case 3:
loop = false;
}
}

}

}


the entire Driver code.


A simple google search for "java nextLine skips" gave me the correct solution so i suggest next time you'll just try googling it first.

As opposed to what you might expect from a method called "nextLine", it doesn't return the whole line but only the part until the EOL characters (basically the enter key). You have to call another input.nextLine() after reading each line, i.e.:


System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
input.nextLine(); // <-- don't need to store output

...



Eh imo the nextLine() method works exactly as you'd expect. It returns all the characters till the next newline character. If it didn't behave this way, you'd end up wondering what happens with a call to nextLine() after something like a call to nextInt().

E.g. if the input were //this is your problem icystorage
1\n //or \r\n
Next line\n

and you call nextInt() to advance to scanner beyond 1 - what should nextLine() return? It should be the empty string, because otherwise that character just gets lost.

I mean if the input were

1 2\n
Next line\n

And you called nextInt() than nextLine(), you'd expect nextLine() to return 2 otherwise it'd be even more confusing.


Well, my definition of "Line" includes the line ending as part of the line. From the first character in the buffer until and including the \n|\r\n. After a call to nextInt, the call to nextLine should from my point of view return just the \n|\r\n. That is why i would expect nextLine to return everything, not needing another call to nextLine to finish the line i requested in the previous nextLine and forcing programmers to use nextLine twice for each line.

However, it's the same behaviour in Java as in C, so i know that it's common to do it the way Java has implemented it but i still don't agree with it... though there are lots of language design decisions in all programming languages that i don't agree with, so it's just a minor point


Wait I don't get what you said - doesn't nextLine() behave the way you'd expect it to? Minus the fact it actually strips the new line characters, it does return all the characters in the buffer until the next new line character (in this case, there are no characters in the buffer till that newline). I'm a little confused as to how this wouldn't require a 2nd call to nextLine().

I'm sure I'm just missing your point so I'd appreciate if you could clarify.


It doesn't strip the EOL characters, it leaves them in the buffer, so you have to call nextLine twice for every line. If it would read the whole line including EOL characters you would only need to call it once per line, which would result in nextLine always returning the real next line, not alternating the line, the EOL, then the line again, then the EOL again, etc.
Fyodor
Profile Blog Joined September 2010
Canada971 Posts
November 30 2012 17:36 GMT
#4106
Is Scala worth learning?

I already know C++, C# and Java. I ask cuz there's a sweet course from the creator himself being offered on Coursera.
llllllllllllllllllllllllllllllllllllllllllll
MichaelEU
Profile Joined February 2011
Netherlands816 Posts
Last Edited: 2012-11-30 18:17:51
November 30 2012 18:16 GMT
#4107
On December 01 2012 02:36 Fyodor wrote:
Is Scala worth learning?

I already know C++, C# and Java. I ask cuz there's a sweet course from the creator himself being offered on Coursera.


Will it land you a job? I don't know, I'm only in my second year myself. Is functional programming awesome? Is the course awesome? Is Scala awesome? Yes! Scala is similar to what you know (Object Oriented) yet different enough (Functional) that it requires a different way of thinking.

In the past year Scala has grown to me to become my favourite language. Of course, the nice thing about Coursera is participation, or your degree thereof, is entirely voluntary.
世界を革命する力を!― znf: "Michael-oniichan ( *^▽^*)ノ✩キラ✩"
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
November 30 2012 19:03 GMT
#4108
On December 01 2012 03:16 MichaelEU wrote:
Show nested quote +
On December 01 2012 02:36 Fyodor wrote:
Is Scala worth learning?

I already know C++, C# and Java. I ask cuz there's a sweet course from the creator himself being offered on Coursera.


Will it land you a job? I don't know, I'm only in my second year myself. Is functional programming awesome? Is the course awesome? Is Scala awesome? Yes! Scala is similar to what you know (Object Oriented) yet different enough (Functional) that it requires a different way of thinking.

In the past year Scala has grown to me to become my favourite language. Of course, the nice thing about Coursera is participation, or your degree thereof, is entirely voluntary.


- It most likely won't land you a job.
- Functional programming is awesome and i recommend everyone to learn it, though i would recommend scheme or lisp for that. I learned scheme and it taught me a lot, eventhough i never actually used it again after playing around with it for a few days.
- No idea.
- Not a fan of Scala myself but learning new languages always gives you new insight into languages you already know so it's never wrong. If you have the opportunity, learn it.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2577 Posts
November 30 2012 20:34 GMT
#4109
The answer to questions in the form of "Is X worth learning?" is always yes. If you have the opportunity and the time to learn a new thing, you should.

^^^^ Life philosophy advice ^^^^

vvvv Programmer career advice vvvv

Learning a new programming language is always valuable. As a general rule, you're only going to get really intimately familiar with the ones you work with professionally (or on a really long term hobby project), but having a passing familiarity with a lot of different programming paradigms can give you very valuable perspective when you're thinking about how to solve a problem. Also, didn't we all start doing this because our dads showed us QBASIC or something and we thought learning to program was super fun? Learning to program is super fun! We should all do more of it!
The frumious Bandersnatch
teamamerica
Profile Blog Joined July 2010
United States958 Posts
November 30 2012 21:50 GMT
#4110
On December 01 2012 01:51 Morfildur wrote:
Show nested quote +
On December 01 2012 00:05 teamamerica wrote:
On November 30 2012 23:01 Morfildur wrote:
On November 30 2012 22:43 teamamerica wrote:
On November 30 2012 22:14 Morfildur wrote:
On November 30 2012 20:49 icystorage wrote:
I'm sorry guys but this is kind of a homework problem and got stuck.
im not really good in Java but how do you fix this problem?

+ Show Spoiler +
[image loading]


the scanner totally skips the 'Enter Student Name' part and directly proceeds to the Enter Student Id.

Did I do something wrong?

the x = null; part is just a hunch coz i thought x wasn't initialized properly.

+ Show Spoiler +
import java.util.Scanner;


public class Driver {


public static void main(String[] args) {

int choice, numberCourses, y;
String x;
Scanner input = new Scanner(System.in);
boolean loop = true;

while(loop == true){

System.out.println("Student Record Menu");
System.out.println("[1] New Record");
System.out.println("[2] Display Records");
System.out.println("[3] Quit");

choice = input.nextInt();

switch(choice) {
case 1:
System.out.println("New Record:");
Record record = new Record();
record.createStudent();

System.out.println("Enter Student Name:");
x = null;
x = input.nextLine();
record.setName(x);

System.out.println("Enter Student ID:");
x = input.nextLine();
record.setId(x);

System.out.println("Enter Course:");
x = input.nextLine();
record.setCourse(x);

System.out.println("Enter number of Subjects:");
numberCourses = input.nextInt();

for (int i = 1; i < numberCourses; i++) {
Course course = new Course();
System.out.println("For Subject " + i);
System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
System.out.println("Enter Description:");
x = input.nextLine();
course.setDesc(x);
System.out.println("Enter Subject Units:");
y = input.nextInt();
course.setUnits(y);
System.out.println("Enter Grade:");
y = input.nextInt();
course.setGrade(y);
record.addCourse(course);
}
System.out.println("Done Adding...");
case 2:
case 3:
loop = false;
}
}

}

}


the entire Driver code.


A simple google search for "java nextLine skips" gave me the correct solution so i suggest next time you'll just try googling it first.

As opposed to what you might expect from a method called "nextLine", it doesn't return the whole line but only the part until the EOL characters (basically the enter key). You have to call another input.nextLine() after reading each line, i.e.:


System.out.println("Enter Subject Code:");
x = input.nextLine();
course.setCode(x);
input.nextLine(); // <-- don't need to store output

...



Eh imo the nextLine() method works exactly as you'd expect. It returns all the characters till the next newline character. If it didn't behave this way, you'd end up wondering what happens with a call to nextLine() after something like a call to nextInt().

E.g. if the input were //this is your problem icystorage
1\n //or \r\n
Next line\n

and you call nextInt() to advance to scanner beyond 1 - what should nextLine() return? It should be the empty string, because otherwise that character just gets lost.

I mean if the input were

1 2\n
Next line\n

And you called nextInt() than nextLine(), you'd expect nextLine() to return 2 otherwise it'd be even more confusing.


Well, my definition of "Line" includes the line ending as part of the line. From the first character in the buffer until and including the \n|\r\n. After a call to nextInt, the call to nextLine should from my point of view return just the \n|\r\n. That is why i would expect nextLine to return everything, not needing another call to nextLine to finish the line i requested in the previous nextLine and forcing programmers to use nextLine twice for each line.

However, it's the same behaviour in Java as in C, so i know that it's common to do it the way Java has implemented it but i still don't agree with it... though there are lots of language design decisions in all programming languages that i don't agree with, so it's just a minor point


Wait I don't get what you said - doesn't nextLine() behave the way you'd expect it to? Minus the fact it actually strips the new line characters, it does return all the characters in the buffer until the next new line character (in this case, there are no characters in the buffer till that newline). I'm a little confused as to how this wouldn't require a 2nd call to nextLine().

I'm sure I'm just missing your point so I'd appreciate if you could clarify.


It doesn't strip the EOL characters, it leaves them in the buffer, so you have to call nextLine twice for every line. If it would read the whole line including EOL characters you would only need to call it once per line, which would result in nextLine always returning the real next line, not alternating the line, the EOL, then the line again, then the EOL again, etc.


nextInt() doesn't strip EOL characters. nextLine() does, and leaves the buffer at the beginning of next line. You don't need to call nextLine() 2x for each line - you need to call it once for each EOL. The situation here is that nextInt() leaves the EOL charater in the buffer, so calling nextLine() the first time advances past that. I can't speak to how C does it but ya.
RIP GOMTV. RIP PROLEAGUE.
Fyodor
Profile Blog Joined September 2010
Canada971 Posts
Last Edited: 2012-12-01 06:36:35
December 01 2012 06:30 GMT
#4111
On December 01 2012 05:34 AmericanUmlaut wrote:
The answer to questions in the form of "Is X worth learning?" is always yes. If you have the opportunity and the time to learn a new thing, you should.

^^^^ Life philosophy advice ^^^^

vvvv Programmer career advice vvvv

Learning a new programming language is always valuable. As a general rule, you're only going to get really intimately familiar with the ones you work with professionally (or on a really long term hobby project), but having a passing familiarity with a lot of different programming paradigms can give you very valuable perspective when you're thinking about how to solve a problem. Also, didn't we all start doing this because our dads showed us QBASIC or something and we thought learning to program was super fun? Learning to program is super fun! We should all do more of it!

I used to be a Philosophy student and I can say with a good degree of confidence that there are some things which are of absolutely no value to learn.

It's happened fairly often that after reading a book or an essay I think to myself "Well my life has been very clearly made worse by me having read this." Happened enough that I quit.

Thanks to the others for the input too. How about Scala compared to "heterogeneous parallel programming" again on Coursera which teaches CUDA C++ and OpenCL.

I'm not a professional programmer right now and don't mind gambling on something which might be valuable in the future.
llllllllllllllllllllllllllllllllllllllllllll
phar
Profile Joined August 2011
United States1080 Posts
December 01 2012 08:19 GMT
#4112
Couple months too late Maybe he'll do it again. Creator of scala teaching scala on coursera:

https://www.coursera.org/course/progfun
Who after all is today speaking about the destruction of the Armenians?
Fyodor
Profile Blog Joined September 2010
Canada971 Posts
December 01 2012 08:30 GMT
#4113
On December 01 2012 17:19 phar wrote:
Couple months too late Maybe he'll do it again. Creator of scala teaching scala on coursera:

https://www.coursera.org/course/progfun

The archive is still up. I'm my own boss right now so I don't care too greatly about the certificate.
llllllllllllllllllllllllllllllllllllllllllll
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
December 01 2012 08:47 GMT
#4114
Anyone know a codecademy-like site for C++?
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
phar
Profile Joined August 2011
United States1080 Posts
December 01 2012 23:21 GMT
#4115
On December 01 2012 17:30 Fyodor wrote:
Show nested quote +
On December 01 2012 17:19 phar wrote:
Couple months too late Maybe he'll do it again. Creator of scala teaching scala on coursera:

https://www.coursera.org/course/progfun

The archive is still up. I'm my own boss right now so I don't care too greatly about the certificate.

Well good, enjoy then Probably no better way to get an introduction to scala.
Who after all is today speaking about the destruction of the Armenians?
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
December 02 2012 00:18 GMT
#4116
On December 01 2012 17:47 Arnstein wrote:
Anyone know a codecademy-like site for C++?


Don't think there is one. I searched for one a while ago. The reason codeacademy has lessons on languages like Python and Javascript is because they are interpretted scripted languages, so implementing interactive lessons with them is much simpler than languages like C++
Undefeated TL Tecmo Super Bowl League Champion
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-02 16:16:12
December 02 2012 15:47 GMT
#4117
Hey, I just started coding but I keep messing up the syntax for else, elif and if statements in Python. Especially when to whitespace and where to put and, or and not. Could someone give me an example? Would be very much appreciated because I just can't figure it out :/
Also, are there other sites like CodeAcademy? I really like the "Review" parts where you have to solve these puzzles and code yourself with help ofcourse, but everything else is kinda boring to me.

Edit: Figured it out with the help of google. Still don't fully understand what whitespace does but atleast my code works. I believe I had no problems in Java with if and else statements.
Apom
Profile Blog Joined August 2011
France655 Posts
December 02 2012 15:59 GMT
#4118
Scala is interesting in that it meshes object and functional programming. I love the language but could never find a use for it in any of my projects (professional or personal). I'd say it's fairly dated though : if I recall correctly, when I learnt it, it was still based on Java 1.4, with Java 1.6 already out.

I would recommend F# over Scala for something "serious" (it's still marginal, but Microsoft is kind of pushing behind it). If it's just for an approach to functional programming, maybe going for a "purer" language would be a better idea (Haskell, one of the ML family languages, Scheme...).
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2012-12-02 21:02:04
December 02 2012 20:56 GMT
#4119
Java: Is it possible to send output across the network to every user within a linked a list? If yes, how? I've tried some google search, but I found nothing.
Fyodor
Profile Blog Joined September 2010
Canada971 Posts
December 02 2012 21:09 GMT
#4120
On December 03 2012 05:56 darkness wrote:
Java: Is it possible to send output across the network to every user within a linked a list? If yes, how? I've tried some google search, but I found nothing.

for each loop? I'm not sure I understand at what level your problem is.
llllllllllllllllllllllllllllllllllllllllllll
Prev 1 204 205 206 207 208 1031 Next
Please log in or register to reply.
Live Events Refresh
WardiTV Summer Champion…
11:00
Playoffs Day 3
Clem vs MaxPaxLIVE!
Classic vs TBD
WardiTV980
TKL 284
IndyStarCraft 185
Rex138
IntoTheiNu 29
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko291
TKL 284
IndyStarCraft 185
Rex 138
SC2_NightMare 22
mcanning 15
StarCraft: Brood War
Britney 70059
Calm 5197
Sea 2406
Jaedong 1856
Horang2 1838
Flash 1811
Bisu 1568
Rain 1533
firebathero 777
ggaemo 747
[ Show more ]
Mini 725
EffOrt 544
Larva 486
Stork 397
BeSt 389
Light 244
hero 220
Zeus 203
Snow 202
Last 171
Soulkey 160
Nal_rA 159
Soma 124
TY 114
Mong 103
NaDa 102
Hyuk 96
Mind 85
Aegong 81
Rush 76
ZerO 65
Movie 51
[sc1f]eonzerg 48
Sharp 47
JulyZerg 46
Sea.KH 41
PianO 35
Sacsri 30
Terrorterran 18
IntoTheRainbow 16
HiyA 14
scan(afreeca) 14
ajuk12(nOOB) 13
Sexy 12
Noble 12
Bale 10
ivOry 3
Dota 2
Gorgc4388
Dendi1251
qojqva1092
420jenkins261
XcaliburYe261
syndereN161
XaKoH 126
Counter-Strike
fl0m2258
olofmeister2061
byalli253
markeloff112
Other Games
singsing2143
B2W.Neo1442
hiko782
DeMusliM357
Fuzer 314
crisheroes313
Hui .248
Happy118
RotterdaM98
ArmadaUGS59
ZerO(Twitch)19
Organizations
Other Games
Algost 5
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 1010
• WagamamaTV527
League of Legends
• Jankos1733
Upcoming Events
Replay Cast
10h 9m
LiuLi Cup
21h 9m
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
1d 2h
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
Big Brain Bouts
1d 2h
Iba vs GgMaChine
TriGGeR vs Bunny
Reynor vs Classic
Serral vs Clem
BSL Team Wars
1d 5h
Team Hawk vs Team Dewalt
BSL Team Wars
1d 5h
Team Hawk vs Team Bonyth
SC Evo League
1d 22h
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
Maestros of the Game
2 days
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[BSL 2025] Weekly
2 days
SC Evo League
2 days
[ Show More ]
Maestros of the Game
3 days
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
3 days
Team Bonyth vs Team Sziky
BSL Team Wars
3 days
Team Dewalt vs Team Sziky
Monday Night Weeklies
4 days
Replay Cast
4 days
Sparkling Tuna Cup
4 days
Replay Cast
6 days
The PondCast
6 days
RSL Revival
6 days
Maru vs SHIN
MaNa vs MaxPax
Liquipedia Results

Completed

CSL Season 18: Qualifier 1
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
Acropolis #4 - TS1
CSL Season 18: Qualifier 2
SEL Season 2 Championship
WardiTV Summer 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.