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

Write a program that uses nested for loops to produce the following output: & &&

ID: 3662414 • Letter: W

Question

Write a program that uses nested for loops to produce the following output:

&
&&
&&&
&&&&
&&&&&
&&&&&&

Write a program that prompts the user for the length, width, and height of a rectangular box. Have the program calculate and display the surface area and volume of the box. Continue to prompt the user for a set of new box dimensions and output the calculated surface area and volume until a zero or negative dimension is entered.

Write a program that determines if a user entered integer is a prime number. A prime number is an integer greater than 1 that can be divided evenly only by 1 or itself. Examples of prime numbers are: 3, 5, 7, 11 and 13. (Hint: Use a while loop and an if statement incorporating the modulo operator.) The output should look like the following with an explanation if it not a prime:

Enter an integer to be tested if a prime number: 9
The number is not prime because it is divisible by 3

Enter an integer to be tested if a prime number: 5683
The number is a prime.

Write a program that reads input until encountering the # character and then reports the number of spaces read, the number of new line characters read, and the number of all other characters read.

Write an encryption program that reads in a single sentence up to the period. The program outputs the modified sentence with all of the spaces removed and replaces each of the vowels with the letter 'Z'.

Explanation / Answer

//First Program

public class Triangle
{  
  
   public static void main(String s[])
   {
      for(int i=1;i<=6;i++)
      {
         for(int j=0;j<i;j++)
            System.out.print("&");
         System.out.println(" ");
      }     
      
   }
}

// Second Program

import java.util.*;

public class Box
{  
  
   public static void main(String s[])
   {
       double height, width, length, area, vol;
      Scanner in;
      while(true)
      {
        System.out.println("Enter length");
         in = new Scanner(System.in);
         length = in.nextDouble();
       
         System.out.println("Enter width");
         in = new Scanner(System.in);
         width = in.nextDouble();
       
         System.out.println("Enter height");
         in = new Scanner(System.in);
         height = in.nextDouble();

         if(width>0 && height>0 && length>0)
         {
            area=length*width;
            vol=length*width*height;
            System.out.println(" Area of box is "+area+" Volume of box is "+vol);

          
         }
         else
         {
            System.out.println(" Invalid Data: Exiting");
            break;
          
         }
       
      }
    
      
   }
}

// Third Program Prime No

import java.util.*;

public class PrimeNumber
{  
  
   public static void main(String s[])
   {
       int n,m;
      boolean f=false;
      Scanner in;
      System.out.println("Enter an integer to be tested if a prime number:");
      in = new Scanner(System.in);
      n = in.nextInt();
    
      if(n<2) System.out.println("Number less than 2, please enter number greater than 1" );
      else
      {
         for(int i=2;i<n;i++)
         {
           m=n%i;
           if(m==0)
           {
            System.out.println("The number is not prime because it is divisible by "+i);
            f=true;
            break;
           }
         }
         if(!f) System.out.println("The number prime" );
              
      }
    
      
   }
}

// Fourth Program Counting characters

import java.util.*;
import java.io.*;

public class MultiplePrograms
{  
  
   public static void main(String s[])
   {
     try
     {
      int spaces,lines,other;
      Scanner in;
      spaces=lines=other=0;
      char c=' ';
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter characters, '#' to quit.");
      // read characters
      do
      {
         c = (char) br.read();
         if(c==' ')
              spaces++;       // if its space increment spaces counter
         else if(c==' ')
              lines++;        // if its new line increment lines counter

         else if(c!='#')
              other++;
           
       }
      while(c != '#');    
      System.out.println("Read "+spaces+" spaces, "+lines+" new line characters and "+other+" other characters");      
    }
    catch (Exception e)
    {
      System.out.println(e);
    }
   }
}

// Fifth Program:" Encryption

import java.util.Scanner;
import java.io.*;

class EncryptString
{


   public static void main(String args[])
   {
      String s,enc;

      System.out.println("Enter the sentence");
      Scanner in = new Scanner(System.in);
      s = in.nextLine();
    
      // Replace all vowels ith 'Z'
      enc=s.replace('a', 'Z');
      enc=enc.replace('e', 'Z');
      enc=enc.replace('i', 'Z');
      enc=enc.replace('o', 'Z');
      enc=enc.replace('u', 'Z');
    
      // Remove all spaces
    
      enc=enc.replaceAll(" ", "");
      
      System.out.println("Encrypted String is "+enc);
   }
}

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