Java Programs with Output PDF Free Download

Java Programs with Output PDF

Name

Java Programs with Output

Language

English

Source

Multiple Source

Category

Education

406 KB

File Size

37

Total Pages

29/11/2023

Last Updated


Java Programs with Output PDF Free Download

If you are looking for the Java Programs for Freshers Practise PDF then you are in the right place. At the end of this post, we added a button to download the Java Interview Programs with Output/Solutions PDF for free.

Java Programs

In this post, we have shared the Java Programs with Output. This will be helpful for the students for their exams. The students can obtain questions for practice and help them to revise the questions and answers for each topic before exams.

Java-Programs

This post will help beginners to understand various Java Programming Examples along with the Outputs.  The post will contain various programs like simple hello world program, adding two numbers, printing pyramid in Java, etc., which can be helpful for freshers to understand the syntax and logic of Java programming.

Java Hello World Programs

  • The Class keyword is used to declare a class in Java
  • The Public keyword is an access modifier that represents visibility, which means this function is visible to all.
  • Static is a keyword, used to make a static method. The advantage of the static method is that there is no need to create an object to invoke the static method. The main()
  • The Method here is called by JVM, without creating any object for the class.
  • Void is the return type of the method, it means this method will not return anything.
  • Main: The main() method is the most important method in a Java program. It represents the startup of the program.
  • String[] args is used for command line arguments.
  • System.out.println() is used to print statements on the console

Leap Year Program in Java

import java.util.Scanner;
public class Lear_year {
 public static void main(String args[]) {
  Scanner s = new Scanner(System.in);
  System.out.print("Enter any year:");
  
  int year = s.nextInt();
  
  boolean flag = false;
  
  if (year % 400 == 0) {
   flag = true;
  } else if (year % 100 == 0) {
   flag = false;
  } else if (year % 4 == 0) {
   flag = true;
  } else {
   flag = false;
  }
  if (flag) {
   System.out.println("Year " + year + " is a Leap Year");
  } else {
   System.out.println("Year " + year + " is not a Leap Year");
  }
 }
}

Output :

Enter any year:2015
Year 2015 is not a Leap Year

Enter any year:2016
Year 2016 is a Leap Year

Checkout:

Download Java Programs with Output PDF

To download Java Programs with Output PDF, just click on the below download button. Within a few seconds, this PDF will be on your device.

Leave a Comment