In this tutorial i am going to show you how to create a program to check max number in java . to do that follow these steps or simply watch my video.
- First create a notepad file and open it
- Give a name and Save the notepad file with .java (Ex: - max.java)
- Make sure the save as type is All Files
- Then delete the notepad file if you want and edit the java file with a text editor
- Paste or write down the code (code is below the tutorial) and make sure the class name is equal to the name that given to save the file.
- Save the file and close it
- open CMD (Command Prompt)
- Set the JDK bin folder path coding by %path%; (Ex:- set path=%path%;C:\Program Files\Java\jdk1.8.0_112\bin) and press enter
- Set the directory where we saved the java file.
- After that need to compile the java file to create class file. simple type - javac filename.java (Ex:- javac max.java)
- To run the program type java filename (Ex:- java max)
To download JDK :- http://allinone-nsr.blogspot.com/p/jdk.html
IF YOU ARE A BEGINNER CHECK MY HELLO WORLD PROGRAM CREATED BY JAVA. IN THAT THERE ARE IMAGES SHOWN HOW TO CREATE A JAVA PROGRAM STEP BY STEP.
The code is : -
import java.util.Scanner;
class max{
public static void main(String[] args){
int max=0;
System.out.println("Enter Number 1:-");
Scanner a = new Scanner(System.in);
int num1=a.nextInt();
System.out.println("Enter Number 2:-");
Scanner b = new Scanner(System.in);
int num2=b.nextInt();
if(num1>num2){
max=num1;
}
else{
max=num2;
}
System.out.println("Maximum Number is: - "+max);
}
}
No comments:
Post a Comment