NETBEANS Java Basics 106 – Getting Inputs
PREREQUISITE
Download NetBeans from https://netbeans.org/downloads/
STEPS
1) Open the Startup Project.
Refer previous tutorial, http://javadevsteps.blogspot.com/2014/08/netbeans-java-basics-101-getting-started.html .
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 );
}
}
|
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;
}
}
|
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: ");
}
}
|
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( );
}
}
|
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.
No comments:
Post a Comment