0% found this document useful (0 votes)
9 views

Programming

The document contains Java code examples for basic arithmetic operations, finding the largest number among three inputs, and reversing an array of integers. Each section includes user input prompts and outputs the results of the operations. The code demonstrates fundamental programming concepts such as loops, conditionals, and array manipulation.

Uploaded by

cyrus3620
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
9 views

Programming

The document contains Java code examples for basic arithmetic operations, finding the largest number among three inputs, and reversing an array of integers. Each section includes user input prompts and outputs the results of the operations. The code demonstrates fundamental programming concepts such as loops, conditionals, and array manipulation.

Uploaded by

cyrus3620
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
package assignment; impo publ , = java-util-scanner; @author Admin 5 Arithmeticoperation ( command line argum * @param args t public static void maim(string{] args) ( ToDo code application logic here Scanner scanner = new Scanner (System. in); system. out.printin("enter First Number:"); int firstnumber = scanner.nextint()7 system. out.printin("Enter Second Number int secondnumber = scanner-nextInt(); int sum = firstnumber + secondnumber; int difference = firstnumber - secondnumber: int product = firstnumber * secondaumbe System. cut.printin("Your sum is: "+sum); system. out.printin("rhe difference is: "+difference): system. out.printin("rhe Product is: "+product): Qutput - Assignment (run) SES your sum is: 16 The difference is: ~ The Product is: 63 BUILD SUCCESSFUL (total time: 17 seconds) import java.util.Scanner: public class LargestNumber( public static void maim(String[] args) { new Scanner (System. in Scanner scanner mine the large: 2": // Input thr to de System.out.print ("Enter the first numbe: number int numl = scanner.nextInt (); System.out.print ("Enter the second number: " int num2 = scanner.nextint(); System.out-print ("Enter the third numbe: int num3 = scanner.nextInt ()+ est numb ert int largest; if (numi >= num2 eg numl >= num3) { largest = numl: } else if (mum2 >= num1 && num2 >= num3) { largest = num2; }els= { largest = num3; y // Display the largest number System.out.printIn("The largest number is: Output - Assignment (run) SH?F Enter the first number: 8 Enter the second number: 4 Enter the third number: 5 ‘The largest number is: 8 + lergest); BUILD SUCCESSFUL (total time: 1 minute 14 seconds) i) Gl import java-util.scanner: 2 3 public class Reversearray ( A public static void madn(string[] args) { 5 Scanner scanner = new Scanner (System. in); € 7 vi © an array to store 5 inti 8 int(] numbers = new int(S]; 2 10 // Input 5 integers an System. out.printin ("Enter 5 integer values:"); 12 for (int i = 0; i < 5; itt) { 13 System. cut.print ("Enter value "+ (i #1) +": 14 numbers[i] = scanner-nextint(); 15 y 16 a7 // show the values in reverse order ae system. out printin ("Reverse order:"); as © for (int i= 4; i >= 07 i--) [ 20 system, cut.print (numbers{i] +" "): a1 y 22 y 23} 24 Output - Assignment (run) Enter 5 integer values: enter value 1: Enter value 2: Enter value 3: SEF Enter value 4 wowrs enter value 5: Reverse Order: 9 8 3.7 5 BUILD SUCCESSFUL (total time: 13 seconds)

You might also like