Write a JAVA program to display following pattern You first

Write a JAVA program to display following pattern. You first need to read number of rows and columns and based on it your patter should be. For example, if you road 5 as row value and 4 as column value then, your pattern should look like: If you read 10 as row value and 5 as column value then, your pattern should look like: Write a JAVA program to read a number from user and then find out all prime numbers up to that number. For Example, if user enters 10, then your program should show: The prime number up to 10 are: 2, 3, 5, 7 if user enters 0, then your program should show: The prime number up to 10 are: 2, 3, 5, 7, 11, 13, 17, 19

Solution

1 : Program

import java.util.Scanner;
public class pattern
{
  
public static void main(String args[])
{
int m,n;
Scanner in = new Scanner(System.in);
System.out.println(\"Enter the number of rows and columns of matrix\ \");
m = in.nextInt();
n = in.nextInt();
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
if(j%2==1)
{
System.out.print(\"*\\t\");
}
else
{
System.out.print(\"-\\t\");
}
}
System.out.print(\"\ \");
}
}
}

2 Program :

import java.util.Scanner;

public class primenumber {
public static void main(String[] args)
{
int n,p;
Scanner in = new Scanner(System.in);
System.out.println(\"Enter a number\ \");
n = in.nextInt();
System.out.println(\"The prime numbers upto \" + n + \" are\");
for(int i=2;i<n;i++)
{
p=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
p=1;
}
if(p==0)
  
System.out.print(i+\"\\t\");
}
}
  
}

 Write a JAVA program to display following pattern. You first need to read number of rows and columns and based on it your patter should be. For example, if you
 Write a JAVA program to display following pattern. You first need to read number of rows and columns and based on it your patter should be. For example, if you

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site