SOFT255SL Software Engineering For The Internet Using Java Acadamic Year 2020
SOFT255SL Software Engineering For The Internet Using Java Acadamic Year 2020
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] );
}
}
}
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 + " ");
}
}
}
}