Day 4 Assignment 1
Day 4 Assignment 1
(Total Marks 5)
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
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}
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
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)