NAME: FAVOUR ISATU YILLAH
I.D: I-24-63541
DEPARTMENT: INFORMATION TECHONOLOGY (I.T)
FACULTY: THE FACULTY OF INFORMATION SYSTEM TECHNOLOGY
THE PRACTICE PROGRAM FOR LECTURE FIVE OF ONE (5.1). (ITERATIVE STATEMENT)
Q1.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner fav = new Scanner(System.in);
/*Write a program that displays the multiplication table
up to 12 iterations for any positive integer given by the user.
For example, if the user inputs 6, your program should display
the multiplication table for 6 for up to 12 iterations
(i.e. 6*1 = 6, 6*2 =12, 6*3 = 18, ……… 6*12 = 72.
*/
System.out.print("Enter a number from 1-12: ");
int number = profbock.nextInt();
for (int a = 0; a <= 12; a++) {
System.out.println(number +"x"+ a + "=" +(number * a));
}
}
}
Q2.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner fav = new Scanner(System.in);
//Write a program that prints all the odd numbers between 12 and 100.
for (int y=12; y<=100; y++) {
if (y%2==1){
System.out.println(y);
}
}
}
}
Q3.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner fav = new Scanner(System.in);
// Write a program to calculate the sum of the first 20 natural odd numbers.
int j=0;
for (int i=0;i<=20;i++) {
j += i;
}
System.out.println(j);
}
}
Q4.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner fav = new Scanner(System.in);
//Program to print Fibonacci series using for loop.
System.out.print("Input the Number of terms:");
int terms = profbock.nextInt();
System.out.println("Fibonacci Series");
int first_term = 0, second_term = 1;
for (int b = 0; b < terms; b++) {
System.out.println(first_term);
int next_term = first_term + second_term;
first_term =second_term;
second_term=next_term;
}
}
}
Q5.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner fav = new Scanner(System.in);
//Use a while loop to sum the first 10 natural numbers.
int sum = 0;
int num = 1;
while (num <= 10) {
sum += num;
num++;
}
System.out.println(sum);
}
}
Comments
Post a Comment