Is there anyway to solve below problem in Java?
Wherever there is int it gives an error! It's not only line 20! it give an runtime error everywhere get int after string! or even before read string!
cities[i] = sc.next(); //This way does not work!!!!
==============
input
San Francisco Las Vegas 8 San Diego Los Angeles San Francisco San Jose Sacramento Santa Barbara Las Vegas Pheonix 8 19 0 1 0 3 1 0 1 2 1 4 1 3 2 1 2 5 2 6 2 7 3 7 3 0 3 1 4 7 4 1 5 2 6 2 7 2 7 3
==============
Error:
==============
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Solution.main(myFuncs.java:20)
=======================
==============
import java.io.*;
import java.util.*;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class myFuncs{
public static void main(String arg[]) {
Scanner sc = new
Scanner(System.in);
String s1, s2;
s1 = sc.nextLine();
//first city
s2 = sc.nextLine();
//second city
int n = sc.nextInt();
//total number of cities
String cities[] = new
String[n];
for (int i = 0; i <
n; i++) {
cities[i] = sc.nextLine(); //getting each city and storing
them
}
n = sc.nextInt();
int e =
sc.nextInt();
int adj[][] = new
int[n][e];
for (int i = 0; i <
n; i++)
for (int j = 0; j < e; j++)
adj[i][j] = 0;
for (int i = 0; i <
e; i++) {
int c1 = sc.nextInt();
int c2 = sc.nextInt();
adj[c1][c2] = 1;
adj[c2][c1] = 1;
}
int index1 = -1, index2 = -1;
for (int i = 0; i
< n; i++) {
if (cities[i].equals(s1)) index1 = i; //storing the index of first
city
if (cities[i].equals(s2)) index2 = i; //storing the index of second
city
}
adj[index1][index2] =
0;
adj[index2][index1] =
0;
System.out.println(cities[index1] + " " + index1);
System.out.println(cities[index2] + " " + index2);
if (bfs(adj, index1,
index2, n)) System.out.println("true");
else
System.out.println("false");
}
public static boolean bfs(int adj[][], int source, int dest, int V) {
boolean visited[] = new boolean[V];
LinkedList < Integer > queue = new LinkedList < Integer > ();
visited[source] =
true;
//visited[dest]=true;
queue.add(source);
while (queue.size()
!= 0) {
int s = queue.poll();
if (queue.size() != 0)
queue.remove();
System.out.print(s + " ");
for (int i = s; i < V; i++) {
if (adj[s][i] == 1 && !visited[i]) {
visited[i] = true;
queue.add(i);
if (i == dest) return true;
}
}
}
return false;
}
}
In: Computer Science
If the statement is true, prove it. Otherwise give a counter example.
a)If V=C3 and W1={(z1,z2,z2)∈C3:z1,z2∈C}, W2={(0,z,0)∈C3:z∈C}, then V=W1⊕W2.
b)If Vis a vector space and W1, W2 are subspaces of V, then W1∪W2 is also a subspace of V.
c)If T:V→V is a linear operator, then Ker(T) and Range(T) are invariant under T.
d)Let T:V→V be a linear operator. If Ker(T)∩Range(T) ={0}, then V=Ker(T)⊕Range(T).
e)If T1,T2:V→V are linear operators such that T1T2=T2T1, and λ2 is an eigenvalue of T2, then Ker(T2−λ2I) is invariant under T1.
In: Accounting
According to the author, what three kinds of information can be learned from international comparisons of health care systems and What sorts of questions might arise about health care politics being common or different among countries? (500 words) In your own words No plagiarizm
In: Economics
In your reading assignment, “Engaging With Children and Young People” by Mary Kellett, the author suggested methods for more effective communication.
Mention three “pearls” that you will utilize in practice involving general and/or specific pediatric populations.
https://epubs.scu.edu.au/cgi/viewcontent.cgi?article=1029&context=ccyp_pubs/
In: Nursing
In: Statistics and Probability
Find an article relating to Cost of Capital or Capital Budgeting from any medium, briefly summarize the article, explain how you found the article particularly useful or timely, and give your personal reactions to the article. Be sure to provide the title of the article, the author(s), and the reference for the article.
In: Finance
In: Nursing
IN C++ PLEASE:
(1) Extend the ItemToPurchase class per the following
specifications:
(2) Create three new files:
Build the ShoppingCart class with the following specifications. Note: Some can be function stubs (empty functions) initially, to be completed in later steps.
In: Computer Science
In: Statistics and Probability
Question 7
In Santa Monica, California, it was reported that a “finder’s fee”—an up-front payment of up to $5,000—was being required of prospective tenants seeking to rent special apartments. What is this an example of?
the black market
a price floor
price gouging
a government price ceiling
Question 8
Mesa Petroleum Company built a small park in front of its corporate office. This is an example of __________.
imposing external costs on its shareholders
providing a pure public good
providing external benefits to the community
assuming city responsibilities
Question 9
What is the most frequently cited example of an externality?
service charges
public protest
pollution
sales taxes
Question 10
A negative externality exists when __________.
all costs are taken into account in the demand curve
all costs are taken into account in the supply curve
the market demand curve is not the true demand curve
the marginal social costs are not taken into account in the supply cur
In: Economics