0% found this document useful (0 votes)
6 views

Java Lab1

Uploaded by

harsha14203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java Lab1

Uploaded by

harsha14203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1) Hello, Word!

class HARSHA {

public static void main(String[] args) {

System.out.println("Hello, World!");

2)fibonacci series

class Main {

public static void main(String[] args) {

int n = 10, firstTerm = 0, secondTerm = 1;

System.out.println("Fibonacci Series till " + n + " terms:");

for (int i = 1; i <= n; ++i) {


System.out.print(firstTerm + ", ");

// compute the next term

int nextTerm = firstTerm + secondTerm;

firstTerm = secondTerm;

secondTerm = nextTerm;

3.check positive or negative or zero

class Check

public static void main(String args[])


{

int num=-2546;

if(num>0)

{ System.out.println("Number is positive ");}

if(num<0)

{System.out.println("number is negative");}

else

{System.out.println("number is zero");}

4)prime or not

class Primecheck{
public static void main(String args[]){

int i,m=0,flag=0;

int n=3;

m=n/2;

if(n==0||n==1){

System.out.println(n+" is not a prime number.");

else{

for(i=2;i<=m;i++){

if(n%i==0){

System.out.println(n+" is not a prime number.");

flag=1;

break;

if(flag==0) { System.out.println(n+" is a prime number."); }

}
5)Bio data

class Bio

public static void main(String[] args)

int age,rollnum,fathername,mothername;

age=18;

rollnum=40;

System.out.println("name of the student is :"+"V.SRI HARSHA");

System.out.println("Age of students is ="+age);

System.out.println("Roll number of the student is :"+rollnum);

}
6)biggest and smallest of 3

import java.util.Scanner;

class Bigandsmall{

public static void main (String args[]){

Scanner scan=new Scanner(System.in);

System.out.print("Enter the first number: ");

int num1=scan.nextInt();//get input from user for num1

System.out.print("Enter the second number: ");

int num2=scan.nextInt();//get input from user for num2

System.out.print("Enter the third number: ");

int num3=scan.nextInt();//get input from user for num3

if(num1<=num2 && num1<=num3){

System.out.println("\n The Smallest number is: "+num1);

}
else if(num2<=num1 && num2<=num3){

System.out.println("\n The Smallest number is: "+num2);

else{

System.out.println("\n The Smallest number is: "+num3);

if(num1>=num2 && num1>=num3){

System.out.println("\n The Smallest number is: "+num1);

else if(num2>=num1 && num2>=num3){

System.out.println("\n The Smallest number is: "+num2);

else{

System.out.println("\n The largest number is: "+num3);

You might also like