Saturday, August 16, 2014

NETBEANS Java Basics 106 – Getting Inputs

---
NETBEANS Java Basics 106 – Getting Inputs

PREREQUISITE

Download NetBeans from https://netbeans.org/downloads/ 

STEPS

1) Open the Startup Project.

package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        // TODO code application logic here
    }  
}

2) EDIT THE CODES.

2-1) Add:
a) A Scanner library import declaration statement (in the import declaration section).
package firstproject;
import java.util.Scanner;
public class FirstProject {
    public static void main(String[] args) {
        // TODO code application logic here
    }  
}
b) A Scanner object declaration statement (in the main method)
package firstproject;
import java.util.Scanner;
public class FirstProject {
    public static void main(String[] args) {
                Scanner user_input = new Scanner( System.in );
    }  
}
c) A String variable declaration statement (in the main method)
package firstproject;
import java.util.Scanner;
public class FirstProject {
    public static void main(String[] args) {
                Scanner user_input = new Scanner( System.in );
                String first_name;
    }  
}
d) An input request output statement (in the main method)
package firstproject;
import java.util.Scanner;
public class FirstProject {
    public static void main(String[] args) {
                Scanner user_input = new Scanner( System.in );
                String first_name;
                System.out.print("Enter your first name: ");
    }  
}
e) A String input statement (in the main method)
package firstproject;
import java.util.Scanner;
public class FirstProject {
    public static void main(String[] args) {
                Scanner user_input = new Scanner( System.in );
                String first_name;
                System.out.print("Enter your first name: ");
                first_name = user_input.next( );
    }  
}
f) A String output statement (in the main method)
package firstproject;
import java.util.Scanner;
public class FirstProject {
    public static void main(String[] args) {
                Scanner user_input = new Scanner( System.in );
                String first_name;
                System.out.print("Enter your first name: ");
                first_name = user_input.next( );
                System.out.println("You are " + first_name);
    }  
}
2-2) Run.

3) FURTHER EDITS

Task: Write codes to achieve the following outcome.
Hint: Use a variable full_name to combine the first name and family name.

REFERENCE

---

No comments:

Post a Comment