Answer-1
class PrimeNumbers
{
public static void main (String[] args)
{
int i =0;
int num =0;
//Empty String
String primeNumbers = "";
for (i = 1; i <= 100; i++)
{
int counter=0;
for(num =i; num>=1; num--)
{
if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2)
{
//Appended the Prime number to the String
primeNumbers = primeNumbers + i + " ";
}
}
System.out.println("Prime numbers from 1 to 100 are :");
System.out.println(primeNumbers);
}
}
Answer-2
public class DivisibleChecker {
public static void main(string [] args) {
int num1, num2;
num1 = 32;
num2 = 12;
if (num1 % num2 == 0) {
System.out.println("The first number is divisible by the second number");
} else {
System.out.println("The first number is not divisible by the second number");
}
}
}
Answer-3
public class table {
public static void main(String [] args)
int result;
for (int i = 1; i <=10; i++) {
result = i * 5;
system.out.println("5 * " + i " = " + result);
}
}
}
Answer-4
No comments:
Post a Comment