You are on page 1of 11

INSTITUTE OF SOFTWARE ENGINEERING

GRADUATE DIPLOMA IN SOFTWARE ENGINEERING

ASSIGNMENT NAME
Programming fundamentals
ASSIGNMENT NO
04

NUMBER OF QUESTIONS: 35
NUMBER OF COMPLETED QUESTIONS: 35
NUMBER OF REMAINING QUESTIONS: 00

STUDENT NAME: Pamudu Mihiranga


NIC: 200202601728
BATCH NO: 64
(1.) import java.util.Scanner;
class Demo{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int x;
int y;
System.out.print("enter your first number :");
x=scan.nextInt();
System.out.print("enter your senod number :");
y=scan.nextInt();
if(x<=y){
System.out.println("your numbers total :"+(x+y));
}
System.out.printf("your first number and second number is :"+x+" , "+y);
}
}

(2.) import java.util.Scanner;


class Demo{
public static void main(String[]args){
char ch='a';
int x=ch;
System.out.println(x);
}
}
(3.) import java.util.Scanner;

class Demo{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int count=2;
System.out.print("Entuer your Physics marks :");
int Physics_marks=scan.nextInt();
System.out.print("Entuer your Combined maths marks :");
int Combinedmaths_marks=scan.nextInt();
int total=Physics_marks+Combinedmaths_marks;
double avg=(double)total/count;
//System.out.println("Chemistry marks total :"+total);
//System.out.println("Chemistry marks avg :"+avg);
if(avg>75){
System.out.println("pass");
}else{
System.out.println("fail");
}
}
}

(4.) import java.util.Scanner;

class Demo{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.print("Enter unit price :");
int unit_price=scan.nextInt();
System.out.print("Enter unit amount product :");
int amount_product=scan.nextInt();
int total=unit_price*amount_product;
//System.out.println(total);
if(total>=1500){
System.out.println("You are entitled for the super draw");
}else{
System.out.println("try again");
}
}
}

(5.) import java.util.Scanner;


class e5{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.print("Enter unit price :");
int unit_price=scan.nextInt();
System.out.print("Enter unit amount product :");
int amount_product=scan.nextInt();
double total=unit_price*amount_product;
System.out.println("your bill :"+total);
if(total>500){
System.out.println("give 5% discount");
double discount=total*0.05;
double amount=total-discount;
System.out.println("New total bill :"+amount+"\n"+"Discount :"+discount);
}
else{
System.out.println("No discount given");
}
}
}
(6.) import java.util.Scanner;
class e6{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.print("Get enter Year:");
int year=scan.nextInt();
boolean flag = false;
if(year%4==0){
flag=true;
}else if(year%100==0){
flag=false;
}else if(year%400==0){
flag=true;
}
if(flag){
System.out.println("Year is a Leap Year");
}else{
System.out.println("Year is not a Leap Year");
}
}
}

(7.) import java.util.Scanner;


class e7{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.print("input the radius :");
double radius=scan.nextDouble();
double area_of_a_circle=(radius*radius)*22/7;
System.out.println(area_of_a_circle);
}
}
(8.) import java.util.Scanner;
class Demo{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int balance=5000;
int withdraw;
int desposit;
System.out.print("Choose 1 for Withdraw :");
withdraw=scan.nextInt();
int daily_limit =2000;
double current=5000*0.02;
if(daily_limit>=withdraw){
balance=balance-withdraw;
System.out.println("Please collect your money :"+balance);
}else {
System.out.println("daily limt over :");
}
System.out.print("Enter money to be deposited :");
desposit=scan.nextInt();
balance=balance+desposit+(int)current;
System.out.println("your new balance:"+balance);
}
}

(9.) import java.util.Scanner;


class Demo{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.print("Enter yor fst number :");
int fst=scan.nextInt();
System.out.print("Enter yor snd number :");
int snd=scan.nextInt();
System.out.print("Enter yor trd number :");
int trd=scan.nextInt();
if(fst>snd)
if(fst>trd)
System.out.println("Maximum number is :"+fst);
if(snd>fst)
if(snd>trd)
System.out.println("Maximum number is :"+snd);
if(trd>fst)
if(trd>snd)
System.out.println("Maximum number is :"+trd);
}
}

(10.) import java.util.Scanner;


class Demo{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.print("Enter your integer number :");
int number=scan.nextInt();
if(number%2==1){
System.out.println(number+" "+"odd number ");
}else{
System.out.println(number+" "+"even number ");
}
}
}

(11.) C
E
F

(12.) A
B
C
D
E
F

(13.)
A.) 9
B.) false
C.) error
D.) false
E.) true

(14.)
A.) true
B.) true
C.) true
D.) false
E.) true
F.) false
G.) true

(15.)
++x==x : 100
x==x++ : 100
++x==x++ : 101

(16.)
++x==x : 101
x==x++ : 102
++x==x++ : 109

(17.) x++==y : 100 : 99


x==++y : 101 : 101
++x==++y : 102 : 102
x++==y++ : 103 : 103
(18.) C
D
G
H
(19.)
A.) failed
B.) succes
C.) failed
D.) failed

(20.) error

(21.) error.
Not data type.

(22.)
line 1 : 10
line 2 : true
line 3 : error
line 4 : true
line 5 : true
line 6 : false

(23.)
A.) 1 2 3
B.) 2 3
C.) 3
D.) 4 1 2 3
E.) 4 1 2 3
F.) 4 1 2 3

(24.) A B C D E F H I

(25.)
A.) 1
B.) 2 3 1
C.) 3 1
D.) 4
E.) 4
F.) 4

(26.)
A.) 0
B.) 0
C.) error
D.) error
G.) 0
H.) 0

(27.) d.) Compiler error :variable d might not have been initialized.

(28.) D.) prints 0 0

(29.) B
D
H

(30.) B
C
D
E

(31.) Compiler error.

(32.)
line 1 : 37
line 2 : Exception in thread "main" java.lang.ArithmeticException: / by
zero
line 3 : error
line 4 : -13.34999999999999
line 5 : 5.625
line 6 : error
line 7 : 15.0
line 8 : 6
line 9 : -10.000000000000028
line 10 : 10
line 12 : -9
line 13 : 4
line 14 : 4
line 15 : 2

(33.)
2 3 4 5 10
14 12 9 5 24
55555

(34.)
line 1 : false
line 2 : true
line 3 : true
line 4 : true
line 5 : false
line 6 : true
line 7 : true
line 8 : flase

(35.)
false
false
true
fals

You might also like