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

In STS, create one Java project for the homework with a separate package for eac

ID: 3849795 • Letter: I

Question

In STS, create one Java project for the homework with a separate package for each question, and use comments liberally in your code: Perform a bubble sort on the following integer array: 1, 0, 5, 6, 3, 2, 3, 7, 9, 8, 4 Write a program to display the first 25 Fibonacci numbers beginning at 0. Reverse a string without using a temporary variable. Do NOT use reverse() in the StringBuffer or the StringBuilder APls. Write a program to compute N factorial. Write a substring method that accepts a string str and an integer idx and returns the substring contained between 0 and idx-1 inclusive. Do NOT use any of the existing substring methods in the String, StringBuilder, or StringBuffer APls. Write a program to determine if an integer is even without using the modulus operator (%) Sort two employees based on their name, department, and age using the Comparator interface.

Explanation / Answer

Question 1

import java.util.Scanner;
public class Sort
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int i,n,j,temp;
System.out.println("Enter the size of the array"); //taking the input size of the array
n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter the values in the array"); //accepting the number in the array
for(i=0;i<n;i++)
a[i]=sc.nextInt();
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1]) //soritng the array
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("The sorted array is");
for(i=0;i<n;i++) //printitng the sorted array
System.out.println(a[i]);
}
}

Question 2

public class fibo
{
public static void main(String []args)
{
int a,b,c,i,n=25; //variable declaration
a=0;
b=1;
c=0;
n=n-2;
System.out.println(a);
System.out.println(b);
for(i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
System.out.println(c); //printing the factorial
}
}
}


Question 3

import java.util.Scanner;
public class Reverse
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
String str,str1; //varaible declaration
int l,i;
char ch;
str="";
str1="";
System.out.println("Enter a string"); //accepting the string from user
str=sc.next();
l=str.length();
for(i=l;i>=0;i--) //reverse a string
{
ch=str.charAt(i);
str1=str1+ch;
}
System.out.println("The reverse string is"); //printitng the reverse string
System.out.println(str1);
}
}


Question 4

import java.util.Scanner;
class facto
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int f,n;
System.out.println("Enter a number");
n=sc.nextInt(); //accepting the number from user
f=1;
while(n!=0)
{
f=f*n; //calculate the factorial
n=n-1;
}
System.out.println("The factorial of the number is "+f); //printing the factorial
}
}

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