0% found this document useful (0 votes)
12 views3 pages

Day 4 Assignment 1

The document provides 10 programming assignments involving data type conversions, loops, arrays, conditional statements, user input, and printing patterns. The assignments cover basic Java concepts like loops, arrays, conditional statements, user input, and switch statements.

Uploaded by

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

Day 4 Assignment 1

The document provides 10 programming assignments involving data type conversions, loops, arrays, conditional statements, user input, and printing patterns. The assignments cover basic Java concepts like loops, arrays, conditional statements, user input, and switch statements.

Uploaded by

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

Day 4 – Assignment 1

(Total Marks 5)

1) Convert below data types using Widening and Narrowing.

int a = 500;
long b = 7823;
double c = 34.5d;
float d = 78.3f;

Convert as follows

1. convert double c value to integer. What is this concept called? (Manual casting or Automatic casting)?
2. convert integer a value to double. What is this concept called? (Manual casting or Automatic casting)?
3. convert float d value to double. What is this concept called? (Manual casting or Automatic casting)?
4. convert long b value to a. What is this concept called? (Manual casting or Automatic casting)?

2) Write code to print “Evotech” 5 times using FOR Loop, While Loop, and Do While loop
Expected output

1 Evotech
2 Evotech
3 Evotech
4 Evotech
5 Evotech

3) What is the different between While loop and do While loop?


_____________________________________________________

4) Loop Following array using For loop and For each Loop
String[] Names={“Amal”, “Asanka”, “Nimali”, “Wimal”, “Akiff”}

5) Write Java code to identify odd and even numbers and store in separate arrays (oddarr, evenarr).

int[] numbers={0,1,2,3,4,5,6,7,8,9,10,11}

int [] oddarr = new int[6];


int [] evenarr = new int[6];
6) What are the following code output?
i) int mark =10;
String ans = (mark>=45)? “Pass”: “Failed”;

ii)
int a = 10, b=20;
if((a!=b) || (b>=21)){
System.out.println(a);
}else if((b!=12) && (a>=9)){
System.out.println(b);
}

7) Take three numbers from the user and print the greatest number. (Use Scanner)

Example Input:
Input the 1st number: 25
Input the 2nd number: 78
Input the 3rd number: 87

Expected Output :
The greatest: 87

8. Write a program in Java to display the multiplication table of a given integer.

Input
Input the number : Input number of terms : 5
Expected Output :

5X0=0
5X1=5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25

9) Write a Java program that keeps a number from the user and generates an integer between 1 and 7 and
displays the name of the weekday. (Use Scanner and Switch Statement)

Test Data
Input number: 3

Expected Output :
Wednesday
10)Write a program to print the following star pattern. (Use for loops)

A) B)

You might also like