Skip to document
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.

Java Labcycle 1 - Simple(Basic) Java Programs with outputs for each.

Simple(Basic) Java Programs with outputs for each.
Course

Bachelor of Computer Applications (BCA2020)

999+ Documents
Students shared 2571 documents in this course
Academic year: 2020/2021
Uploaded by:
0followers
84Uploads
105upvotes

Comments

Please sign in or register to post comments.

Preview text

LAB CYCLE 1

Question 1

Write a program to add two numbers using command line arguments.

Aim

Find a java program to add two numbers using the numbers as command line arguments. Program

class Add{

public static void main(String[] args){

int a,b,sum=0;

a=Integer(args[0]);

b=Integer(args[1]);

sum=a+b; System.out("Sum of " +a + " and " + b + " = " + sum);

}

}

Output

Output

Question 3 Write a program to print fibonacci series upto 'n'. Aim Find a java program to get the fibanocci series upto the number (n) inputted by the user. Program import java.io; public class Fibonacci{ public static void main(String[] argu){ int n=0,n1=0,n2=1,i; System.out("Enter the range: "); DataInputStream in=new DataInputStream(System); try{ n=Integer(in()); } catch(Exception e){ System.out("Error Occured while inputting...!"); } System.out("Fibonacci Numbers upto " + n + "\n========================="); System.out("\n" +n1+ " " +n2); for(i=2;i<n;++i){ int n3=n1+n2; if(n3<=n){ System.out(" " +n3); n1=n2; n2=n3; } }

Output

Question 4

Write a program to generate prime numbers between two numbers.

Aim

Find a java program to generate prime numbers between two numbers which are inputted from user.

Program import java.io;

public class PrimeNumbers{

public static void main(String[] args){

int min=0,max=0;

DataInputStream in=new DataInputStream(System);

System.out("Enter two numbers so that the prime numbers between them to be generate: ");

try{

min=Integer(in());

max=Integer(in());

}

catch(Exception e){

System.out("Error occured while Entering value"); }

System.out("Prime numbers between " +min + " and "+max+ " are " );

if(min==1){

min=2;

}

while (min < max) {

Output

Question 5 Write a program to read a number and count it's number of digits,find sum of digits and display the results. Aim Find a java program to read a number and calculate it's number of digits and sum of digits and print the results. Program import java.io; class Number{ public static void main(String[] args){ int x=0,rem,sum=0,count=0; DataInputStream input =new DataInputStream(System); System.out("Enter a number: "); try{ x=Integer(input()); } catch(Exception e){ System.out("Error occured while inputting ...!"); } System.out("The entered number is "+x); int temp=x; while(x!=0){ rem=x%10; count++; sum=sum+rem; x=x/10; } System.out("The number of digits in "+temp +" = " +count);

  • Question

Write a program to find the roots of a quadratic equation. Aim Find a java program to find the root of a quadratic equation whose coefficients and constant were inputted form the user. Program import java.io; import java.lang; class QuadraticRoot{ public static void main(String[] argu){ double a=0,b=0,c=0; DataInputStream in=new DataInputStream(System); System.out("Enter values of coefficients a,b and constant c: "); try{ a=Double(in()); b=Double(in()); c=Double(in()); } catch(Exception e){ System.out("Error occured while inputting ...!"); } if(a==0){ System.out("It is not a quadratic equation"); System(0); } double d=(bb)-(4a*c); double s=Math(d); if(d<0){

Output

Question 7

Write a program to print Floyd's triangle. Aim Find a java program to display Floyd's triangle. Program import java.io; class FloydTriangle{ public static void main(String args[]){ int rows=0, number = 1, i, j; DataInputStream input = new DataInputStream(System); System.out("Enter the number of rows for floyd's triangle:"); try{ rows = Integer(input()); } catch(Exception e){ System.out("Error occured during inputting...!"); } System.out("Floyd's triangle"); System.out("****************"); for ( i = 1 ; i <= rows ; i++ ) for(s=1;s<=rows-i;s++) System.out(" "); for ( j = 1 ; j <= i ; j++ ) System.out(""+number+" "); number++; System.out(); } }

Was this document helpful?
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.

Java Labcycle 1 - Simple(Basic) Java Programs with outputs for each.

Course: Bachelor of Computer Applications (BCA2020)

999+ Documents
Students shared 2571 documents in this course
Was this document helpful?

This is a preview

Do you want full access? Go Premium and unlock all 19 pages
  • Access to all documents

  • Get Unlimited Downloads

  • Improve your grades

Upload

Share your documents to unlock

Already Premium?
LAB CYCLE 1
Question 1
Write a program to add two numbers using command line arguments .
Aim
Find a java program to add two numbers using the numbers as command line arguments .
Program
class Add{
public static void main(String[] args){
int a,b,sum=0;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
sum=a+b;
System.out.println("Sum of " +a + " and " + b + " = " + sum);
}
}

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.