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

SOFT255SL Software Engineering For The Internet Using Java Acadamic Year 2020

The document contains lab sheets and answers for a software engineering course. Lab Sheet 1 contains 5 questions asking the student to write Java programs to: 1) print the sum of two numbers, 2) swap two numbers, 3) perform basic math operations, 4) print an index using while and do-while loops, and 5) find the square root of a number. Lab Sheet 2 contains 4 questions asking the student to: 1) print numbers from 10 to 100 using loops, 2) check if a number is even or odd using if/else and switch statements, 3) print odd numbers from 0-10 using continue, and 4) print command line arguments using a for-each loop. The document

Uploaded by

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

SOFT255SL Software Engineering For The Internet Using Java Acadamic Year 2020

The document contains lab sheets and answers for a software engineering course. Lab Sheet 1 contains 5 questions asking the student to write Java programs to: 1) print the sum of two numbers, 2) swap two numbers, 3) perform basic math operations, 4) print an index using while and do-while loops, and 5) find the square root of a number. Lab Sheet 2 contains 4 questions asking the student to: 1) print numbers from 10 to 100 using loops, 2) check if a number is even or odd using if/else and switch statements, 3) print odd numbers from 0-10 using continue, and 4) print command line arguments using a for-each loop. The document

Uploaded by

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

SOFT255SL Software Engineering for the Internet Using Java

ACADAMIC YEAR 2020

o Name-:N.D.Manula Sajjana Narasingha


o ID -:10024747
o Batch-:19.1 Software Engineering(PLYMOUTH)
 LAB SHEET 01
1. Write a java program to print the sum of two numbers.
2. Write a java program to swap two numbers.
3. Write a java program to perform four basic arithmetic operations. (Sum,
Subtraction, multiplication and division) When calculating division your
answer should contain decimal points.
4. Write a while loop to print your index number 5 times. Do the same
using a do while loop.
5. Write a java program to find the square root value of a number.

Answer FOR LAB 01


1. public class LAB {
public static void main (String[]args){
System.out.println(48+24);
}

2. ublic class LAB{


public static void main(String[] args) {
float first = 1.20f, second = 2.45f;
System.out.println("--Before swap--");
System.out.println("First number = " + first);
System.out.println("Second number = " + second);
// Value of first is assigned to temporary
float temporary = first;
// Value of second is assigned to first
first = second;
// Value of temporary (which contains the initial value of first) is assigned to second
second = temporary;
System.out.println("--After swap--");
System.out.println("First number = " + first);
System.out.println("Second number = " + second);
}
}

3.)
import java.util.Scanner;
public class LAB
{
public static void main(String args[])
{
int first, second, add, subtract, multiply;
float devide;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Two Numbers : ");
first = scanner.nextInt();
second = scanner.nextInt();
add = first + second;
subtract = first - second;
multiply = first * second;
devide = (float) first / second;
System.out.println("Sum = " + add);
System.out.println("Difference = " + subtract);
System.out.println("Multiplication = " + multiply);
System.out.println("Division = " + devide);
}
}

4.)
class LAB {
public static void main(String args[]){
int i=13;
while(i>1){
System.out.println(i);
i--;
}
}
}
5.)
public class LAB {
public static void main(String args[]) {
Double num;
Scanner sc= new Scanner(System.in);
System.out.print("Enter a number: ");
num=sc.nextDouble();
Double square = num*num;
System.out.println("Square of "+ num + " is: "+ square);
}
}

 LAB SHEET 02
1. Write a java a program to print all numbers from 10 to 100 using all three
looping constructs.
2. Write a java program to check if a given number is even or odd. Use both
conditional constructs. (switch and if)
3. Write a java program to print all the odd numbers from 0-10. Use branching
statements. (continue)
4. Write the same code using a for-each.
public class CommandLineExample{
public static void main( String[] args ){
for(int i=0; i<args.length; i++){
System.out.println( args[i] );
}
}
}

ANSWER FOR LAB 02

1.)
class LAB {
public static void main(String args[]){
for(int i=100; i>10; i--){
System.out.println("The value of i is: "+i);
}
}
}

2.)
IF STATEMENT
public class LAB {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = reader.nextInt();
if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}

SWITCH STATEMENT
public class LAB {
public static void main (String args[]){
int num1=100;
//int num2=111;
switch(num1%2){//this will return 0
case 0:
System.out.println(num1+" is an Even number");
break;
case 1:
System.out.println(num2+" is an Odd number");
}
}
}

3.)
class LAB {
public static void main(String args[]) {
int n = 10;
System.out.print("Odd Numbers from 1 to "+n+" are: ");
for (int i = 1; i <= n; i++) {
if (i % 2 != 0) {
System.out.print(i + " ");
}
}
}
}

You might also like