You are on page 1of 6

Objective:

To understand Java programming basics. In this laboratory, students are expected to learn, java condtional
statements and loops.

NAME: KAINAT GHANI


ROLL NO: 22SP-030-CS
COURSE TEACHER: SIR JUNAID ALI
LAB NUMBER: 02
TASK 1:

package l2;

import java.util.Scanner;

public class grade {

public static void main (String[] args) {

double science, maths, itc, english, programming, average;

Scanner myObj= new Scanner(System.in);

System.out.println("Write your Science marks: ");

science= myObj.nextDouble();

System.out.println("Write your Maths marks: ");

maths= myObj.nextDouble();

System.out.println("Write your Intro to Computation marks: ");

itc= myObj.nextDouble();

System.out.println("Write your English marks: ");

english= myObj.nextDouble();

System.out.println("Write your Programming marks: ");

programming = myObj.nextDouble();

average= (science + maths + itc + english+ programming)/ 5 ;

if (average>88)

System.out.println("Congratulations! You have got A Grade! ");


}

else

if (average>70 && average<88)

System.out.println("Congratulations! You have got B Grade! ");

else

System.out.println("Congratulations! You have got C Grade! ");

}}

TASK 2:
package l2;

import java.util.Scanner;

public class swap {

public static void main (String[] args) {

int val, secval, m=10;

Scanner myObj= new Scanner(System.in);

System.out.println("Enter a value: ");

val = myObj.nextInt();

while(val>0)

secval = val % m;
val = val / m;

System.out.print(secval);

}}

TASK 3:

package l2;

import java.lang.*;

import java.io.*;

import java.util.Scanner;

public class palindrome {

public static void main (String[] args) {

String term;

Scanner myObj= new Scanner(System.in);

System.out.println("Check if your term is Palindrome or not : ");

System.out.println("Write any word: ");

term= myObj.nextLine();

StringBuffer term2 = new StringBuffer(term);

term2.reverse();

if (term.equals( term2.toString()))

System.out.println("YES");

else {
System.out.println(new StringBuffer(term));

}}

TASK 4:
package l2;

public class pattern {

public static void main (String[] args) {

int m=5;

for ( int i=0; i<5; i++)

for ( int j=0; j<=i; j++)

{System.out.print("*");

System.out.println();

System.out.println();

System.out.println();

for ( int i=0; i<4; i++)

{ m= m-1;

for(int k=m; k>0; k--)

{ System.out.print(" ");}
for ( int j=0; j<=i; j++)

System.out.print("*");

System.out.println();

}}

You might also like