SlideShare a Scribd company logo
1 of 1
Problem 7 write a code that will ask the user to input a vector of values F. Then calculate the
number of positive and negative values in that vector. Don't use any built-in functions (eag sum,
find, abs, max, min, etc Example: (four positive values [3 8 1910 N-3 (three negative values [-2 -
4 -7 l)
Solution
import java.util.Scanner; public class JavaProgram { public static void main(String args[]) { int
countp=0, countn=0, countz=0, i; int arr[] = new int[10]; Scanner scan = new
Scanner(System.in); System.out.print("Enter 10 Numbers : "); for(i=0; i<10; i++) { arr[i] =
scan.nextInt(); } for(i=0; i<10; i++) { if(arr[i] < 0) { countn++; } else if(arr[i] == 0) { countz++;
} else { countp++; } } System.out.print(countp + " Positive Numbers"); System.out.print(" "
+ countn + " Negative Numbers"); System.out.print(" " + countz + " Zero"); } }

More Related Content

Similar to Problem 7 write a code that will ask the user to input a vector of val.docx

import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
anupamfootwear
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
deepua8
 
import java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdfimport java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdf
apexelectronices01
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdf
arihanthtoysandgifts
 

Similar to Problem 7 write a code that will ask the user to input a vector of val.docx (15)

Java file
Java fileJava file
Java file
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
 
The java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdfThe java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdf
 
Oot practical
Oot practicalOot practical
Oot practical
 
C#.net
C#.netC#.net
C#.net
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
 
import java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdfimport java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdf
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdf
 

More from shawnk7

An Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docxAn Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docx
shawnk7
 
Although objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docxAlthough objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docx
shawnk7
 
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docxProject 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
shawnk7
 

More from shawnk7 (13)

An IP datagram has arrived with the following information in the heade.docx
An IP datagram has arrived with the following information in the heade.docxAn IP datagram has arrived with the following information in the heade.docx
An IP datagram has arrived with the following information in the heade.docx
 
An Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docxAn Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docx
 
An economy is characterized by the following behavioral equations- C -.docx
An economy is characterized by the following behavioral equations- C -.docxAn economy is characterized by the following behavioral equations- C -.docx
An economy is characterized by the following behavioral equations- C -.docx
 
An auditor examines a sample of cancelled checks to verify that the ch.docx
An auditor examines a sample of cancelled checks to verify that the ch.docxAn auditor examines a sample of cancelled checks to verify that the ch.docx
An auditor examines a sample of cancelled checks to verify that the ch.docx
 
All of the following are false regarding apportionment except- a Ap.docx
All of the following are false regarding apportionment except-    a Ap.docxAll of the following are false regarding apportionment except-    a Ap.docx
All of the following are false regarding apportionment except- a Ap.docx
 
Also indicate all zero-force members- Check all that apply- Check all.docx
Also indicate all zero-force members- Check all that apply- Check all.docxAlso indicate all zero-force members- Check all that apply- Check all.docx
Also indicate all zero-force members- Check all that apply- Check all.docx
 
Although objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docxAlthough objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docx
 
prove or disprove that H - {n e(element) Z- n is divisible by both 8.docx
prove or disprove  that H - {n e(element) Z- n is divisible by both 8.docxprove or disprove  that H - {n e(element) Z- n is divisible by both 8.docx
prove or disprove that H - {n e(element) Z- n is divisible by both 8.docx
 
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docxProject 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
 
Problem 9-11A Time Value of Money Concept The following situations inv.docx
Problem 9-11A Time Value of Money Concept The following situations inv.docxProblem 9-11A Time Value of Money Concept The following situations inv.docx
Problem 9-11A Time Value of Money Concept The following situations inv.docx
 
Problem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docx
Problem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docxProblem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docx
Problem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docx
 
Problem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docx
Problem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docxProblem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docx
Problem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docx
 
Problem 11-6A Problem 11-6A Irwin Corporation has been au.docx
Problem 11-6A             Problem 11-6A  Irwin Corporation has been au.docxProblem 11-6A             Problem 11-6A  Irwin Corporation has been au.docx
Problem 11-6A Problem 11-6A Irwin Corporation has been au.docx
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Problem 7 write a code that will ask the user to input a vector of val.docx

  • 1. Problem 7 write a code that will ask the user to input a vector of values F. Then calculate the number of positive and negative values in that vector. Don't use any built-in functions (eag sum, find, abs, max, min, etc Example: (four positive values [3 8 1910 N-3 (three negative values [-2 - 4 -7 l) Solution import java.util.Scanner; public class JavaProgram { public static void main(String args[]) { int countp=0, countn=0, countz=0, i; int arr[] = new int[10]; Scanner scan = new Scanner(System.in); System.out.print("Enter 10 Numbers : "); for(i=0; i<10; i++) { arr[i] = scan.nextInt(); } for(i=0; i<10; i++) { if(arr[i] < 0) { countn++; } else if(arr[i] == 0) { countz++; } else { countp++; } } System.out.print(countp + " Positive Numbers"); System.out.print(" " + countn + " Negative Numbers"); System.out.print(" " + countz + " Zero"); } }