Java Week2(A) Notepad

348 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
348
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java Week2(A) Notepad

  1. 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

×