1. JAVA WEEK2(A)
/*
Week 2 : a) Write a Java program that prompts the user for an integer and then
prints out all prime numbers up to that integer. */
import javax.swing.*;
public class week2(A)
{
public static void main(String args[])
{
String n1;
int n,c=0,i,j;
n1=JOptionPane.showInputDialog("enter n value");
n=Integer.parseInt(n1);
outer:
for(i=2;i<=n;i++)
{
for(j=2;j<=(i/2);j++)
{
if(i%j==0)
continue outer;
}
JOptionPane.showMessageDialog(null,i+" ");
}
}
}
Page 1