Java Lecture 5
Java Lecture 5
Java Lecture 5
Lecture 5
Patterns - Part 1
1.
import java.util.*;
Apna College
2.
import java.util.*;
Apna College
3.
import java.util.*;
Apna College
4.
import java.util.*;
Apna College
5.
import java.util.*;
Apna College
6.
import java.util.*;
Apna College
7.
import java.util.*;
Apna College
8.
import java.util.*;
Apna College
9.
import java.util.*;
Apna College
Homework Problems (Solutions in next Lecture’s Video)
1. Print a solid rhombus.
Apna College
Homework Solution (Lecture 4)
3. int n = 25;
4.
6. if(i % 2 == 0) {
7. System.out.println(i);
8. }
9. }
10. }
11. }
12.
3. Make a menu driven program. The user can enter 2 numbers, either 1 or 0.
If the user enters 1 then keep taking input from the user for a student’s
marks(out of 100).
Apna College
(Hint : use do-while loop but think & understand why)
import java.util.*;
do {
int marks = sc.nextInt();
if(marks >= 90 && marks <= 100) {
System.out.println("This is Good");
} else if(marks >= 60 && marks <= 89) {
System.out.println("This is also Good");
} else if(marks >= 0 && marks <= 59) {
System.out.println("This is Good as well");
} else {
System.out.println("Invalid");
}
} while(input == 1);
}
}
[In this problem you will learn how to check if a number is prime or not]
import java.util.*;
Apna College
if(n % i == 0) {
isPrime = false;
break;
}
}
if(isPrime) {
if(n == 1) {
System.out.println("This is neither prime not composite");
} else {
System.out.println("This is a prime number");
}
} else {
System.out.println("This is not a prime number");
}
}
}
Apna College