Simple Java Program
1. Open Notepad, type these lines and save as MyName.java
import java.util.*;
public class MyName {
public static void main (String[] args) {
Scanner s=new Scanner(System.in);
System.out.print ("Enter name: ");
String tname=s.nextLine();
System.out.println ("Hello " + tname);
}
}
2. Compile from cmd line. Output program will be named MyName.class
javac MyName.java
3. Run the program. Output is shown as below
java MyName
Enter name: Ray
Hello Ray
Tips : Download NetBeans from https://netbeans.org/ to get graphical tool for coding instead of simple notepad
import java.util.*;
public class MyName {
public static void main (String[] args) {
Scanner s=new Scanner(System.in);
System.out.print ("Enter name: ");
String tname=s.nextLine();
System.out.println ("Hello " + tname);
}
}
2. Compile from cmd line. Output program will be named MyName.class
javac MyName.java
3. Run the program. Output is shown as below
java MyName
Enter name: Ray
Hello Ray
Tips : Download NetBeans from https://netbeans.org/ to get graphical tool for coding instead of simple notepad
0 Comments:
Post a Comment
<< Home