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

AT&T; LTE 12:06 PM 67% docs.googleusercontent.com 1. Write a Program to use arra

ID: 3920298 • Letter: A

Question

AT&T; LTE 12:06 PM 67% docs.googleusercontent.com 1. Write a Program to use arrays. 2. Write a program to copy one array's elements to another array without using array function. 3. Reverse a string using array. Hint: accept string value in store in a string variable str. Then convert str into array as follow: charl ch-str.ToCharArray; 4. Shows difference between checked statements and unchecked statements in C# using . Write a program of enumeration in which store three value in enumeration red, yellow and green and shows their numeric position. by writing suitable C# code in which display the user option and based on 6. Shows difference between break and continue 7. Write a program for library management system c: for computer books m: for mathematical books h: for history books e: for English books If user input wrong value then shows them message try again and serve the input prompt again using goto label statement. 8. Write a program to implement list of objects. Input a number from user and displays power of the number. Ask user's to whether continue or not. If user presses y or Y then continue and again accept a number. If user presses any other characters or numbers then quit. (Use while loop) Using for loop print the following output in web 121 12321 1234321 123454321

Explanation / Answer

1. PROGRAM

import java.util.Scanner;

// create main class ArrayProgram
class ArrayProgram
{
public static void main(String [] args)
{
Scanner scr=new Scanner(System.in); // create Scanner Object scr
int [] a=new int[10]; // declare integer array a

System.out.println("Enter 10 Random Array Elements: ");
for(int i=0;i<10;i++) // create for loop until 10 elements
a[i]=scr.nextInt(); // read array elements

System.out.println("Array Elements are");
for(int i=0;i<10;i++) // create for loop until 10 elements
System.out.print(a[i]+" "); // display array elements
}
}

OUTPUT


F:>javac ArrayProgram.java

F:>java ArrayProgram
Enter 10 Random Array Elements:
55
8
25
13
48
69
82
99
156
259
Array Elements are
55 8 25 13 48 69 82 99 156 259

2. PROGRAM

import java.util.Scanner;

class CopyArray
{
public static void main(String [] args)
{
Scanner scr=new Scanner(System.in); // create Scanner Object scr
int [] a=new int[10]; // declare integer array a

System.out.println("Enter 10 Random Array Elements: ");
for(int i=0;i<10;i++) // create for loop until 10 elements
a[i]=scr.nextInt(); // read array elements

System.out.println("Array A Elements are");
for(int i=0;i<10;i++) // create for loop until 10 elements
System.out.print(a[i]+" "); // display array a elements

int [] b=new int[10]; // declare another array integer variable b

// copy existing array element into array b
for(int i=0;i<10;i++)
b[i]=a[i];

System.out.println(" After Copy Array into B Elements are");
for(int i=0;i<10;i++) // create for loop until 10 elements
System.out.print(b[i]+" "); // display array b elements

}

}

OUTPUT

F:>javac CopyArray.java

F:>java CopyArray
Enter 10 Random Array Elements:
1
2
5
99
45
35
6
7
8
92
Array A Elements are
1 2 5 99 45 35 6 7 8 92
After Copy Array into B Elements are
1 2 5 99 45 35 6 7 8 92

3. PROGRAM

import java.util.Scanner;

class ReverseString
{

public static void main(String [] args)
{
Scanner scr=new Scanner(System.in); // create Scanner object scr
String str; // declare string object str
System.out.print("Enter String: ");
str=scr.next(); // read string

char [] ch=str.toCharArray(); // convert given string to character array
System.out.print(" Reverse the given String is: ");
for(int i=ch.length-1;i>=0;i--) // create for loop from length of the string to 0
{
System.out.print(ch[i]); // display reverse string
}

}
}


OUTPUT


F:>javac ReverseString.java

F:>java ReverseString
Enter String: washington

Reverse the given String is: notgnihsaw

4. PROGRAM

using System;

  

class CheckProgram

  

{

  

public short a = 30000;

  

public short b = 20000;

  

public short c;

  

public int sum()

  

{

  

try

  

{

  

c = checked((short)(a + b));

  

}

catch (System.OverflowException e)

  

{

  

System.Console.WriteLine(e.ToString());

  

}

  

return c;

  

}

  

public int mul()

  

{

  

try

  

{

  

checked

{

  

c = (short)(a * b);

  

}

  

}

catch (System.OverflowException e)

  

{

  

System.Console.WriteLine(e.ToString());

  

}

  

return c;

  

}

  

public int sum_Unchecked()

  

{

  

try

  

{

  

c = unchecked((short)(a + b));

  

}

catch (System.OverflowException e)

  

{

  

System.Console.WriteLine(e.ToString());

  

}

return c;

  

}

  

public int mul_Unchecked()

  

{

  

try

  

{

  

unchecked

{

  

c = (short)(a * b);

  

}

  

}

catch (System.OverflowException e)

  

{

  

System.Console.WriteLine(e.ToString());

  

}

  

return c;

  

}

  

static void Main(string[] args)

  

{

  

CheckProgram p = new CheckProgram();

  

// For checked

  

Console.WriteLine("Checked output value is: {0}", p.sum());

  

Console.WriteLine("Checked output value is: {0}", p.mul());

  

// For Unchecked

  

Console.WriteLine("Checked output value is: {0}", p.sum_Unchecked());

Console.WriteLine("Checked output value is: {0}", p.mul_Unchecked());

  

Console.ReadKey(true);

  

}

  

}

OUTPUT

System.OverflowException: Arithmetic operation resulted in an overflow.

at CheckProgram.sum () [0x00000] in <cb17ca2b3a2f41c787700dc409d9e990>:0

Checked output value is: 0

System.OverflowException: Arithmetic operation resulted in an overflow.

at CheckProgram.mul () [0x00000] in <cb17ca2b3a2f41c787700dc409d9e990>:0

Checked output value is: 0

Checked output value is: -15536

Checked output value is: 17920

5. PROGRAM

class EnumTest

{

public enum Color{ RED(1),YELLOW(4),GREEN(5);

int val;

Color(int x){

val=x;

}

int showValue(){

return val;

}

}

public static void main(String [] args)

{

System.out.println("Enumerated List:");

for(Color c: Color.values())

System.out.println(c+" values "+c.showValue());

}

}

OUTPUT

F:>javac EnumTest.java

F:>java EnumTest

Enumerated List:

RED values 1

YELLOW values 4

GREEN values 5

PROGRAM-6

BREAK STATEMENT

using System;

class BreakTest

{

public static void Main(String [] args)

{

for(int i=0;i<=5;i++)

{

if(i==4){ break; }

  

Console.WriteLine("The number is: "+i);

}

}

}

OUTPUT

The number is: 0

The number is: 1

The number is: 2

The number is: 3

CONTINUE STATEMENT

using System;

class ContinueTest

{

public static void Main(String [] args)

{

for(int i=0;i<=5;i++)

{

if(i==4){ continue;}

Console.WriteLine("The number is: "+i);

}

}

}

OUTPUT

The number is: 0

The number is: 1

The number is: 2

The number is: 3

The number is: 5

PROGRAM-7

import java.util.Scanner;

class LibraryMgt

{

public static char Menu()

{

char ch;

Scanner scr=new Scanner(System.in);

System.out.println(" LIBRARY MANAGEMENT ");

System.out.println("c: for computer books");

System.out.println("m: for mathematical books");

System.out.println("h: for history books");

System.out.println("e: for English books");

System.out.print("Enter Your Option: ");

ch=scr.next().charAt(0);

return ch;

}

public static void main(String [] args)

{

char ch;

outer: {

ch=Menu();

if(ch=='c')

System.out.println("Computer Books are Available");

else if(ch=='m')

System.out.println("Mathematics Books are Available");

else if(ch=='h')

System.out.println("History Books are Available");

else if(ch=='e')

System.out.println("English Books are Available");

else {

System.out.println("Try Again...");

break outer;

  

}

}

}

}

OUTPUT

F:>javac LibraryMgt.java

F:>java LibraryMgt

LIBRARY MANAGEMENT

c: for computer books

m: for mathematical books

h: for history books

e: for English books

Enter Your Option: c

Computer Books are Available

F:>java LibraryMgt

LIBRARY MANAGEMENT

c: for computer books

m: for mathematical books

h: for history books

e: for English books

Enter Your Option: s

Try Again...

PROGRAM-9

import java.util.Scanner;

class PowerTest
{
public static void main(String [] args)
{
int num;
char ch;
Scanner scr=new Scanner(System.in);
while(true)
{
System.out.print("Enter Number: ");
num=scr.nextInt();
double pow=Math.pow(num,2);
System.out.println("The Power of "+num+" is "+pow);

System.out.print("Continue or Not (Y/N): ");
ch=scr.next().charAt(0);

if(ch=='n'||ch=='N') System.exit(0);


}

}

}

OUTPUT


F:>javac PowerTest.java

F:>java PowerTest
Enter Number: 2
The Power of 2 is 4.0
Continue or Not (Y/N): y
Enter Number: 5
The Power of 5 is 25.0
Continue or Not (Y/N): y
Enter Number: 9
The Power of 9 is 81.0
Continue or Not (Y/N): n

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