Jump to content

[RESOLVIDO] Scanner?


Ivo Pereira
 Share

Recommended Posts

Boas pessoal,

ao ler uns tutoriaizitos vi uma função que é o Scanner, que permite ler o que o user escrever.

Este é o meu código feito no NetBeans IDE 6.1:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication1;
import java.util.Scanner;
/**
*
* @author Ivo
*/

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner s = New Scanner(System.in);
        System.out.print("|''''''''''''''''''''''''''''''''''''''''''''|\n");
        System.out.print("|-----------Powered by: Ivo Pereira----------|\n");
        System.out.print("|''''''''''''''''''''''''''''''''''''''''''''|\n");
        System.out.print("|                                            |\n");
        System.out.print("|              My first Java app             |\n");
        System.out.print("|            Made in Netbeans IDE            |\n");
        System.out.print("|____________________________________________|\n");
        String linha = s.NextLine();
        System.out.print(linha);
        
    }

}

O que é que está mal aqui?

Dá-me este erro:

init:

deps-jar:

Compiling 1 source file to C:\Users\Ivo\Documents\NetBeansProjects\JavaApplication1\build\classes

C:\Users\Ivo\Documents\NetBeansProjects\JavaApplication1\src\javaapplication1\Main.java:19: ';' expected

        Scanner s = New Scanner(System.in);

1 error

BUILD FAILED (total time: 1 second)

Cumps


Ok.. que ESTUPIDEZ DA MINHA PARTE! O Java é case-sensitive nos objectos, métodos, tudo! É  por isso que isto não reconhecia.

Aqui está o código correcto:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.util.Scanner;
/**
*
* @author Ivo
*/

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.print("|''''''''''''''''''''''''''''''''''''''''''''|\n");
        System.out.print("|-----------Powered by: Ivo Pereira----------|\n");
        System.out.print("|''''''''''''''''''''''''''''''''''''''''''''|\n");
        System.out.print("|                                            |\n");
        System.out.print("|              My first Java app             |\n");
        System.out.print("|            Made in Netbeans IDE            |\n");
        System.out.print("|____________________________________________|\n");
        String linha = s.nextLine();
        System.out.print(linha);   

    }

}

Cumps and ty

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.