DOSA CODE
package B14;
public class num37 {
public static void main(String[] args) {
int dosa=8;
int count =1;
while(count<=3)
{
int total = (dosa/2);
dosa= total+dosa;
count++;
}System.out.println(dosa);
}
}
OUTPUT:27
PRINT NUMBER LIKE THIS: 1 2 3 4 5
package B14;
public class num33 {
public static void main(String[] args) {
int count=1;
while(count<=5)
{
System.out.println("1 2 3 4 5");
count++;
}
}
}
Output:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Without String: using nested while loop
package B14;
public class num38 {
public static void main(String[] args) {
int count = 1;
while (count <= 5) {
int i = 1;
while (i <= 5) {
System.out.print(i + " ");
i++;
}
System.out.println();
count++;
}
}
Output:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
PRINT NUMBER LIKE THIS:1 0 1 0 1
package B14;
public class num34 {
public static void main(String[] args) {
int count=1;
while(count<=5)
{
System.out.println("1 0 1 0 1");
count++;
}
}
}
Output:
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
package Afterfeb4;
public class while4 {
public static void main(String[] args) {
int times = 1;
while (times <= 5) {
int no = 1;
int count = 1;
while (count <= 5) {
System.out.print(no + " ");
no = no - 1;
if (count == 5)
break;
System.out.print(no + " ");
no = no + 1;
count = count + 2;
}
times = times + 1;
System.out.println();
}
}
}
Without String: using nested while loop
package B14;
public class num38 {
public static void main(String[] args) {
int count = 0;
while (count < 5) {
int i = 0;
while (i < 5) {
if (i % 2 == 0) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
i++;
}
System.out.println();
count++;
}
}
}
Output:
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
PRINT 3 TABLES:
package B14;
public class num35 {
public static void main(String[] args) {
int count=1;
while(count<=10)
{
int total=count*3;
System.out.println(count+" * 3 = "+ total);
count++;
}
}
}
OUTPUT:
1 * 3 = 3
2 * 3 = 6
3 * 3 = 9
4 * 3 = 12
5 * 3 = 15
6 * 3 = 18
7 * 3 = 21
8 * 3 = 24
9 * 3 = 27
10 * 3 = 30
FIND LCD OF 100 & 120:
package B14;
public class num {
static int result;
public static void main(String[] args) {
int a = 100;
int b = 120;
int count = 1;
while (count <= a && count <= b) {
if (a % count == 0 && b % count == 0) // print LCD of 100 and 120
{
System.out.println("LCD OF 100 & 120 = " + count + "\n");
result = count;
}
count++;
}
System.out.println("\n" + "Greater no = " + result);
}
}
OUTPUT:
LCD OF 100 & 120 = 2
LCD OF 100 & 120 = 4
LCD OF 100 & 120 = 5
LCD OF 100 & 120 = 10
LCD OF 100 & 120 = 20
Greater no = 20
package B14;
public class num {
static int result;
public static void main(String[] args) {
int a = 100;
int b = 120;
int count = 1;
while (count <= a && count <= b) {
if (a % count == 0 && b % count == 0) // print LCD of 100 and 120
{
System.out.println("LCD OF 100 & 120 = " + count + "\n");
result = count;
break;
}
count++;
}
System.out.println("\n" + "LCD = " + result);
}
}
OUTPUT:
LCD OF 100 & 120 = 1
LCD = 1
**
LCM OF 100 & 120:**
find gcd and find lcm
LCM = (a*b) / (gcd)(a,b)
for ex:lcm=(100*120)/(20)
package B14;
public class num36 {
static int gcd;
public static void main(String[] args) {
int a = 100;
int b = 120;
int count = 1;
while (count <= a && count <= b) {
if (a % count == 0 && b % count == 0) {
System.out.println(count);
gcd = count; // Greatest common divisor
}
count++;
}
System.out.println("GCD of 100 & 120 = " + gcd);
int lcm = (a * b) / gcd;
System.out.println("LCM : " + lcm);
}
}
**
OUTPUT:**
1
2
4
5
10
20
GCD of 100 & 120 = 20
LCM : 600
Top comments (0)