coup 163 tlowchart pro x nt-rid-14527125 2/courses/COMP163005.201810/HW6flowchar
ID: 3871299 • Letter: C
Question
coup 163 tlowchart pro x nt-rid-14527125 2/courses/COMP163005.201810/HW6flowcharts.pdf 113 COMP163 Flowchart Programs For this assignment, you are to write three Java programs using flowcharts as a guide. Note that the flowcharts have different syntax than Java. For example, variables, classes and methods are not declared in the flowcharts You will have to convert the flowchart to a working Java program. When you have written and tested your programs, upload the Java files to Blackboard Problem 2 should be a command line Java application. Either problem 1 or problem 3 must be writen with a Graphical User Interface. For GUI programs, the flowchart should be implemented in the ActionPerformed method I. Write a Java program that determines if a given number is a prime. start Example output: Enter a number 143 not prime read num num %2·07 m. -) print not prime Enter a number 127 prime sqrt= vnum heck a nomber checkExplanation / Answer
import java.util.scanner;
class primeNumber
{
public static void main(String args[])
{
int num,i,flag=0;
Scanner scan=new Scanner(system.in);
System.out.println("Enter the number:");
int num=scan.nextInt();
for(i=1;i<=sqrt(num);i++)
{
if(num%i==0)
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Not a prime Number");
}
else
{
System.out.println("prime Number");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.