Ahmad Izzudin Alifyandra Ahmad Izzudin Alifyandra - 5 months ago 20
Java Question

So i just started learning java in treehouse.com ive done the basics but when i try everything ive learnt there on the intellij idea ide nothing works

So i just started learning java in treehouse.com ive done the basics but when i try everything ive learnt there on the intellij idea ide nothing works.

I've already searched the internet trying to find a solution and I still cant find it, yea I've tried system.out but ive seen other people do it with just typing console too and if I try system.out on readline it doesnt work im literally confused.

I'm used to using the

console.println("Hello world!");


and

String name=console.readln("whats yo name: ");


and stuff like that on the treehouse workspace but everytime i try to do it on intellij idea it keeps getting an error.

it looks like this

package com.company;

import java.io.Console;

public class Main
{
public static void main(String[] args)
{
console.println("dada");



}
}

Answer
Console console = new Console()

This code won't work on IntelliJ.

To take input in an IDE use the following code.

Scanner sc = new Scanner(System.in)
String in = sc.nextLine();
System.out.println(in);

You can also use the older way,

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)));
String in = br.readLine();
Comments