Question

Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1 Se
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM -

import java.util.*;
import java.io.*;
public class Q1{

public static void main(String[] args) {

int num1 , num2 , num3 ;
Scanner sc = new Scanner(System.in);
//defining the scanner object
num1 = sc.nextInt();
//take inpuut for the first number

num2 = sc.nextInt();
//take input for the second number
  
num3 = sc.nextInt();
//take input for the second number
int first,second,third; //these will store the sorted number
if( num1 >= num2 && num1 >= num3){
first = num1;//if num1 is highest
if(num2>num3) //if num2 is second highest
{
second = num2;
third = num3;
} //if num2 is lowest
else
{
second = num3;
third = num2;
}
}

else if (num2 >= num1 && num2 >= num3){
first = num2;//if num2 is highest
if(num1>num3) //if num1 is second highest
{
second = num1;
third = num3;
} //if num1 is lowest
else
{
second = num3;
third = num1;
}
}

else{
first = num3;//if num3 is highest
if(num2>num1) //if num2 is second highest
{
second = num2;
third = num1;
} //if num2 is lowest
else
{
second = num1;
third = num2;
}
}
System.out.println("The number in sorted way are : "+first+" "+second+" "+third);//printing the sorted number
  
}
}

INTENDATION-

6 7 9 10 13 14 1 import java.util. 2 import java.io.*; 3- public class Q1{ 4 5 public static void main(String[] args) { int

3. 4 5 6. 7 -8 else if (num2 >= num1 && num2 >= num3){ first = num2;//if num2 is highest if(numl>num3) //if num1 is second hi

INPUT -

mi-

OUTPUT-

The number in sorted way are : 5 3 1

PROGRAM FOR Q3

import java.util.*;
import java.io.*;
public class Q3{
  
public static int isprime(int n){
  
//for a number to be prime the number should be only divisible by 1 and itself
for(int i =2;i<=n/2;i++)
{
if(n%i==0)
{
//if the number is divisible then return 0
return 0;
}
}
//if number is prime then return 1
return 1;
}

public static void main(String[] args) {

int prime_num = 0 ;
int start = 1;
System.out.println("The first 10 prime number are : ");
  
//loop untill you find 10 prime number
while(prime_num!=10)
{
if(isprime(start)==1)
{
//if number is prime then print it and then increment prime_num
System.out.println(start);
prime_num++;
}
start++;
}
}
}

INTENDATION -

1 import java.util.*; 2 import java.io.*; 3- public class 03{ 4 public static int isprime(int n){ //for a number to be prime

OUTPUT-

The first 10 prime number are 1 2 3 5 7 11 13 17 19 23

SORRY FOR THIS BUT WE ARE ALLOWED TO ANSWER ONLY ONE QUESTION AT A TIME. BUT I ANSWERED TWO FOR YOU , DO TELL ME IF YOU HAVE ANY ISSUES.

Add a comment
Know the answer?
Add Answer to:
Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having trouble with the following programs and wasn't sure whether I did it right....

    I am having trouble with the following programs and wasn't sure whether I did it right. A. Write a program in java using a switch statement which asks the user for their letter grade then prints a message to the student according to the following chart: Average Message A Your work is outstanding! B You are doing good work! C Your work is satisfactory. D You need to work a little harder. F Please see me for extra help! B....

  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

  • home / study / engineering / computer science / computer science questions and answers / Write...

    home / study / engineering / computer science / computer science questions and answers / Write A Second Game Program That Prints A Chart To The Screen Showing The Randomness Of A Die. ... Question: Write a second game program that prints a chart to the screen showing the randomness of a die. Th... Write a second game program that prints a chart to the screen showing the randomness of a die. The game should first prompt the client for...

  • I want to know how to do this assignment!!! Help me please~ The first part of...

    I want to know how to do this assignment!!! Help me please~ The first part of your program should do the following: • Ask the user type of test they took. o (ACT or SAT) • If they said ACT then ask them their score o If their ACT score was between 0 and 7 say "Needs Work" o If their ACT score was between 10 and 20 say "Acceptable" o If they ACT score was above 20 say "Above...

  • PYTHON PART 1) SIMPLE IF STATEMENTS INSIDE A LOOP. The first part of your program should...

    PYTHON PART 1) SIMPLE IF STATEMENTS INSIDE A LOOP. The first part of your program should do the following: • Write a section of code that prints off the numbers from 50 to 100. • It should also print off the letter grade that goes with that number on the same line using an if statement o 0 – 59 = F o 60 – 69 = D o 70 – 79 = C o 80 – 89 = B...

  • C++ assignment Write a program that reads a sequence of integers and prints the following: 1....

    C++ assignment Write a program that reads a sequence of integers and prints the following: 1. The number of odd and even numbers of inputs Use a sentinel value to signal the end of inputs. If the sentinel value is the first you enter, give a message “NO input is entered!”. Input Validation: Do not accept a negative number.

  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • Write a C++ code based this question n this assignment you will create three additional functions...

    Write a C++ code based this question n this assignment you will create three additional functions for each one of the data structures created in class. You will be provided with a header file which you will modify and a demo program for each data structure. If your functions are implemented correctly the demo programs should compile and execute correctly. Part 0 (Comments) 1. Over the course of the semester we have discussed comments for each data structure. Please add...

  • use C++            Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse...

    use C++            Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse any given word. 2. Write a program that will: Ask the user to enter a word. Save the entry as word_entered. Call word_rev on the entry Display the reversed entry (word_entered) 3. Write a function named prime() that determine whether or not a given number n (greater than one) is prime. The algorithm: If n is even then n is not a prime number...

  • using linux terminal NEW YORK CITY COLLEGE OF TECHNOLOGY THE CITY UNIVERSITY OF NEW YORK Department...

    using linux terminal NEW YORK CITY COLLEGE OF TECHNOLOGY THE CITY UNIVERSITY OF NEW YORK Department of Computer Engineering Technology 300 Jay Street, Brooklyn, NY 11201-1909 EMT 2390L - Lab 6 Instructions: Create a new script and name it lab6. Include the following in your script: 1- A global variable named course with "EMT 2390L" assigned to it as default value. 2- A global variable named score that will store a number between 0 and 100. 3. A global variable...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT