Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with this! 1. Write a complete Java program that prompts the user

ID: 3786798 • Letter: P

Question

Please help me with this!


1. Write a complete Java program that prompts the user to enter a nonnegative real number and displays the square root of the number if it is nonnegative or it displays a message that a square root of a negative number is not a real number.

2. Find numbers divisible by 5 and 6. Write a complete Java program that displays all the numbers from 100 to 1,000, ten per line, that are divisible by 5 and 6. Numbers are separated by exactly two spaces

4. Write a complete Java program that prompts the user to enter a positive integer n in order to display n random integers in the range [-10, 20], inclusive. The program should display how many of the integers are negative, the theoretical and experimental probability of a random number in the given range, and it should allow the user to repeat execution of the program.

Explanation / Answer

import java.util.*;

public class decimal {

  
  

   public static void main(String[] args) {

      
       System.out.println(" Enter a nonnegative real number");
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       if(n<0)
       {
           System.out.println(" Number is not real number");

       }
       else
       {
                   System.out.println("Square root of "+n+" is "+Math.sqrt(n));

       }

   }

}

==================================

Output:

akshay@akshay-Inspiron-3537:~$ javac decimal.java
akshay@akshay-Inspiron-3537:~$ java decimal
Enter a nonnegative real number
16
Square root of 16 is 4.0
akshay@akshay-Inspiron-3537:~$ java decimal
Enter a nonnegative real number
-6
Number is not real number

==============================================

import java.util.*;

public class decimal {

  
  

   public static void main(String[] args) {

      
       System.out.println("Numbers divisible by 5 and 6");
       int l=0;

       for (int i=100;i<=1000;i++ )
       {
           if(i%5==0 && i%6==0)
           {
               System.out.print(i+" ");
               l++;
           }
           if(l==10)
           {
               l=0;
               System.out.print(" ");
           }
       }
      
   }

}

==========================================================

akshay@akshay-Inspiron-3537:~$ java decimal
Numbers divisible by 5 and 6
120   150   180   210   240   270   300   330   360   390  
420   450   480   510   540   570   600   630   660   690  
720   750   780   810   840   870   900   930   960   990  

================================================================

import java.util.*;

public class decimal {

  
  

   public static void main(String[] args) {

       int max=20;
       int min=(-10);
       System.out.println("Enter n");
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       Random rn = new Random();
       int c=0;
       for (int i=0;i<n ;i++ )
       {
          
           int num=rn.nextInt(max - min + 1) + min;
           System.out.println(num);
           if(num<0)
               c++;

          
       }
               System.out.println("There are "+c+" negative numbers");

      
      
   }

}

====================================================

Output:

akshay@akshay-Inspiron-3537:~$ javac decimal.java
akshay@akshay-Inspiron-3537:~$ java decimal
Enter n
5
10
-8
4
-8
-5
There are 3 negative numbers

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote