9 Replies - 315 Views - Last Post: 28 January 2018 - 10:53 PM Rate Topic: -----

#1 Lyzone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 18

No errors but no output in console?

Posted 27 January 2018 - 06:42 PM

Hi. So I've started Java within the last 4 days, and some parts are hard like multi-dimensional arrays (I've wrapped my head around it but can't write the code) and right now I'm practicing classes. There are no errors showing up yet there is no output. Can anyone tell me what's wrong with it? Thanks.
https://pastebin.com/jNN0AWfc

Is This A Good Question/Topic? 0
  • +

Replies To: No errors but no output in console?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5143
  • View blog
  • Posts: 13,832
  • Joined: 18-April 07

Re: No errors but no output in console?

Posted 27 January 2018 - 08:30 PM

Are you making sure to, after you start your program, to type something into the console? Keep in mind you have a readline in there (line 25), so it is waiting for you to type something and won't show any output until you type something (based on your program). Other than that, it shows output and all that once you type something and hit enter.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6492
  • View blog
  • Posts: 26,266
  • Joined: 12-December 12

Re: No errors but no output in console?

Posted 27 January 2018 - 11:04 PM

Copy and paste your code directly here in the forum, between code tags, not just as an external link that will disappear.
Was This Post Helpful? 0
  • +
  • -

#4 Lyzone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 18

Re: No errors but no output in console?

Posted 28 January 2018 - 06:04 AM

import java.util.Scanner;
 
class PoliceDatabase {
    String age;
    String name;
    String prescriptions;
    String address;
    String DOB;
    String all;
    String history;
}
public class ForTestsOnly {
    public static void main(String[] args) {
        Scanner userinput = new Scanner(System.in);
       
        PoliceDatabase Drunkdriver = new PoliceDatabase();
            Drunkdriver.age = "Age: 20\n";
            Drunkdriver.name = "Name: Joe Dirt\n";
            Drunkdriver.prescriptions = "Prescriptions: None \n";
            Drunkdriver.address = "Address: 7428 Venido Road \n";
            Drunkdriver.DOB = "Date of Birth: March 14, 1998 \n";
            Drunkdriver.history = "On Record: DUI and Assaulting a Police Officer";
            Drunkdriver.all = Drunkdriver.age + Drunkdriver.name + Drunkdriver.prescriptions + Drunkdriver.address + Drunkdriver.DOB + Drunkdriver.history;
           
            String nextLine = userinput.nextLine();
           
        System.out.println("As you're doing a routine circle around a neighbourhood, you see someone swerving.");
       
        System.out.println("You pull up behind them and do the siren wail thing cops do but dont really have a name for.");
       
        System.out.println("You walk up to the driver window and you can smell the distinct alcohol smell.");
       
        System.out.println("As he is about to say 'I can explain' you cut him off and say 'Give me your ID!'");
       
        System.out.println("He hands you his ID and you say 'Turn off the car and give me the keys.'");
       
        System.out.println("He does so, and you walk back to your car and open the database.");
       
        System.out.println("Joe Dirt");
       
        System.out.println("-----POLICE DATABASE-----");
       
        System.out.println(" ");
       
        System.out.println(Drunkdriver.all);
       
        System.out.println(" ");
       
        System.out.println("-----POLICE DATABASE-----");
       
        System.out.println("As you're getting out of your car, you wonder\nif what he did to the last officer could happen to you.");
       
        System.out.println("You're thinking whether you should let him off the hook or not.");
       
        System.out.println("-----");
       
        System.out.println(".offthehook = let him off the hook");
       
        System.out.println(".arresthim = bring him to jail");
       
        System.out.println("-----");
       
            switch (nextLine) {
                case ".offthehook":
                    System.out.println("You walk to his car and say 'you're off the hook, kid.'");
                    System.out.println("You walk back to your car feeling guilty for letting him off the hook.");
                    System.out.println("You continue with your day as normal.");
                    break;
                case ".arresthim":
                    System.out.println("You walk to his car and say 'sir, get out of the car.'");
                    System.out.println("He gets out of the car.");
                    System.out.println("While he's opening the door, he tries to charge at you, \nbut you step to the side and trip him.");
                    System.out.println("You pin him to the ground and handcuff him.");
                    System.out.println("-----10 minutes later-----");
                    System.out.println("As you're driving to the station, you wonder why he did that.");
                    break;
            }
        userinput.close();
    }
}


Something simple as one of my first "programs" that I can use to memorize switch, case, class, etc
Sorry for double post, can't find edit button.

This post has been edited by ndc85430: 28 January 2018 - 10:49 PM
Reason for edit:: Removed quote of previous post. Please just press "Reply" in future.

Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 7054
  • View blog
  • Posts: 14,732
  • Joined: 16-October 07

Re: No errors but no output in console?

Posted 28 January 2018 - 06:12 AM

View PostLyzone, on 28 January 2018 - 08:04 AM, said:

I don't need to type something into the console yet, the sysouts come first then it wants input, because the input is defined after the sysouts.. or is that not how it works?


Are you sure? Look again:
    public static void main(String[] args) {
        Scanner userinput = new Scanner(System.in);
       
        PoliceDatabase Drunkdriver = new PoliceDatabase();
            Drunkdriver.age = "Age: 20\n";
            Drunkdriver.name = "Name: Joe Dirt\n";
            Drunkdriver.prescriptions = "Prescriptions: None \n";
            Drunkdriver.address = "Address: 7428 Venido Road \n";
            Drunkdriver.DOB = "Date of Birth: March 14, 1998 \n";
            Drunkdriver.history = "On Record: DUI and Assaulting a Police Officer";
            Drunkdriver.all = Drunkdriver.age + Drunkdriver.name + Drunkdriver.prescriptions + Drunkdriver.address + Drunkdriver.DOB + Drunkdriver.history;
           
            String nextLine = userinput.nextLine();
           



Where is that prior "sysout?"
Was This Post Helpful? 1
  • +
  • -

#6 Lyzone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 18

Re: No errors but no output in console?

Posted 28 January 2018 - 08:38 AM

Not trying to be rude, legitimately asking a question, so you don't need to either. I assumed when I typed that I was defining what nextLine means, and I inputted the nextLine string further down. Now that I put that after all the sysouts, it works. Thanks.

I assumed when I typed that I was defining what nextLine means, and I inputted the nextLine string further down. Now that I put that after all the sysouts, it works. Thanks.

This post has been edited by ndc85430: 28 January 2018 - 10:51 PM
Reason for edit:: Removed quote of previous post. Please just press "Reply" in future.

Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3503
  • View blog
  • Posts: 15,835
  • Joined: 20-September 08

Re: No errors but no output in console?

Posted 28 January 2018 - 08:57 AM

There's no need to quote whole posts, especially your own! Just use the Reply button
Was This Post Helpful? 0
  • +
  • -

#8 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1261
  • View blog
  • Posts: 4,057
  • Joined: 12-May 09

Re: No errors but no output in console?

Posted 28 January 2018 - 09:02 AM

View PostLyzone, on 28 January 2018 - 10:38 AM, said:

Not trying to be rude, legitimately asking a question, so you don't need to either. I assumed when I typed that I was defining what nextLine means, and I inputted the nextLine string further down. Now that I put that after all the sysouts, it works. Thanks.


I'm certainly not going to tone police, but I don't think baavgai's tone here was rude at all. I'd consider being ready for FAR worse than somebody simply challenging your assertion in any life persons, let alone software development.
Was This Post Helpful? 0
  • +
  • -

#9 Lyzone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 18

Re: No errors but no output in console?

Posted 28 January 2018 - 04:52 PM

Yes, I thought he was being rude, then I realized he wasn't and I tried to edit it, which ended up quoting my whole post. Is there any way I can edit it?

This post has been edited by ndc85430: 28 January 2018 - 10:51 PM
Reason for edit:: Removed quote of previous post. Please just press "Reply" in future.

Was This Post Helpful? 0
  • +
  • -

#10 ndc85430  Icon User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 701
  • View blog
  • Posts: 2,867
  • Joined: 13-June 14

Re: No errors but no output in console?

Posted 28 January 2018 - 10:53 PM

As you've been asked, please stop quoting the previous post and just use the "Reply" button. I've done the editing for you, as you can only edit your posts after you've reached a certain number of posts (see the FAQ for more info).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1